87 |
static int write_value_labels (struct sfm_writer *, |
static int write_value_labels (struct sfm_writer *, |
88 |
struct variable *, int idx); |
struct variable *, int idx); |
89 |
static int write_rec_7_34 (struct sfm_writer *); |
static int write_rec_7_34 (struct sfm_writer *); |
90 |
|
|
91 |
|
static int write_longvar_table (struct sfm_writer *w, |
92 |
|
const struct dictionary *dict); |
93 |
|
|
94 |
|
static int write_variable_display_parameters (struct sfm_writer *w, |
95 |
|
const struct dictionary *dict); |
96 |
|
|
97 |
|
|
98 |
static int write_documents (struct sfm_writer *, const struct dictionary *); |
static int write_documents (struct sfm_writer *, const struct dictionary *); |
99 |
static int does_dict_need_translation (const struct dictionary *); |
static int does_dict_need_translation (const struct dictionary *); |
100 |
|
|
106 |
|
|
107 |
/* Opens the system file designated by file handle FH for writing |
/* Opens the system file designated by file handle FH for writing |
108 |
cases from dictionary D. If COMPRESS is nonzero, the |
cases from dictionary D. If COMPRESS is nonzero, the |
109 |
system file will be compressed. |
system file will be compressed. If OMIT_LONGNAMES is nonzero, the |
110 |
|
long name table will be omitted. |
111 |
|
|
112 |
No reference to D is retained, so it may be modified or |
No reference to D is retained, so it may be modified or |
113 |
destroyed at will after this function returns. */ |
destroyed at will after this function returns. */ |
114 |
struct sfm_writer * |
struct sfm_writer * |
115 |
sfm_open_writer (struct file_handle *fh, |
sfm_open_writer (struct file_handle *fh, |
116 |
const struct dictionary *d, int compress) |
const struct dictionary *d, int compress, |
117 |
|
short omit_longnames) |
118 |
{ |
{ |
119 |
struct sfm_writer *w = NULL; |
struct sfm_writer *w = NULL; |
120 |
int idx; |
int idx; |
177 |
|
|
178 |
if (dict_get_documents (d) != NULL && !write_documents (w, d)) |
if (dict_get_documents (d) != NULL && !write_documents (w, d)) |
179 |
goto error; |
goto error; |
180 |
|
|
181 |
if (!write_rec_7_34 (w)) |
if (!write_rec_7_34 (w)) |
182 |
goto error; |
goto error; |
183 |
|
|
184 |
|
|
185 |
|
/* Write variable display info. */ |
186 |
|
if ( !write_variable_display_parameters(w, d)) |
187 |
|
goto error; |
188 |
|
|
189 |
|
|
190 |
|
if ( ! omit_longnames ) |
191 |
|
{ |
192 |
|
if (!write_longvar_table (w, d)) |
193 |
|
goto error; |
194 |
|
} |
195 |
|
|
196 |
/* Write record 999. */ |
/* Write record 999. */ |
197 |
{ |
{ |
198 |
struct |
struct |
420 |
write_format_spec (&v->print, &sv.print); |
write_format_spec (&v->print, &sv.print); |
421 |
write_format_spec (&v->write, &sv.write); |
write_format_spec (&v->write, &sv.write); |
422 |
memcpy (sv.name, v->name, strlen (v->name)); |
memcpy (sv.name, v->name, strlen (v->name)); |
423 |
memset (&sv.name[strlen (v->name)], ' ', 8 - strlen (v->name)); |
memset (&sv.name[strlen (v->name)], ' ', SHORT_NAME_LEN - strlen (v->name)); |
424 |
if (!buf_write (w, &sv, sizeof sv)) |
if (!buf_write (w, &sv, sizeof sv)) |
425 |
return 0; |
return 0; |
426 |
|
|
566 |
return 1; |
return 1; |
567 |
} |
} |
568 |
|
|
569 |
|
/* Write the alignment, width and scale values */ |
570 |
|
static int |
571 |
|
write_variable_display_parameters (struct sfm_writer *w, |
572 |
|
const struct dictionary *dict) |
573 |
|
{ |
574 |
|
int i; |
575 |
|
|
576 |
|
struct |
577 |
|
{ |
578 |
|
int32 rec_type P; |
579 |
|
int32 subtype P; |
580 |
|
int32 elem_size P; |
581 |
|
int32 n_elem P; |
582 |
|
} vdp_hdr; |
583 |
|
|
584 |
|
vdp_hdr.rec_type = 7; |
585 |
|
vdp_hdr.subtype = 11; |
586 |
|
vdp_hdr.elem_size = 4; |
587 |
|
vdp_hdr.n_elem = w->var_cnt * 3; |
588 |
|
|
589 |
|
if (!buf_write (w, &vdp_hdr, sizeof vdp_hdr)) |
590 |
|
return 0; |
591 |
|
|
592 |
|
for ( i = 0 ; i < w->var_cnt ; ++i ) |
593 |
|
{ |
594 |
|
struct variable *v; |
595 |
|
struct |
596 |
|
{ |
597 |
|
int32 measure P; |
598 |
|
int32 width P; |
599 |
|
int32 align P; |
600 |
|
} |
601 |
|
params; |
602 |
|
|
603 |
|
v = dict_get_var(dict, i); |
604 |
|
|
605 |
|
params.measure = v->measure; |
606 |
|
params.width = v->display_width; |
607 |
|
params.align = v->alignment; |
608 |
|
|
609 |
|
if (!buf_write (w, ¶ms, sizeof(params))) |
610 |
|
return 0; |
611 |
|
} |
612 |
|
|
613 |
|
return 1; |
614 |
|
} |
615 |
|
|
616 |
|
/* Writes the long variable name table */ |
617 |
|
static int |
618 |
|
write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) |
619 |
|
{ |
620 |
|
char *buf = 0; |
621 |
|
int bufsize = 0; |
622 |
|
|
623 |
|
struct |
624 |
|
{ |
625 |
|
int32 rec_type P; |
626 |
|
int32 subtype P; |
627 |
|
int32 elem_size P; |
628 |
|
int32 n_elem P; |
629 |
|
} lv_hdr; |
630 |
|
|
631 |
|
lv_hdr.rec_type = 7; |
632 |
|
lv_hdr.subtype = 13; |
633 |
|
lv_hdr.elem_size = 1; |
634 |
|
|
635 |
|
|
636 |
|
dict_get_varname_block(dict, &buf, &bufsize); |
637 |
|
|
638 |
|
if ( bufsize == 0 ) |
639 |
|
return 1; |
640 |
|
|
641 |
|
lv_hdr.n_elem = bufsize ; |
642 |
|
|
643 |
|
if (!buf_write (w, &lv_hdr, sizeof(lv_hdr) )) |
644 |
|
goto error; |
645 |
|
|
646 |
|
if (!buf_write (w, buf, bufsize)) |
647 |
|
goto error; |
648 |
|
|
649 |
|
return 1; |
650 |
|
|
651 |
|
error: |
652 |
|
free ( buf ) ; |
653 |
|
return 0; |
654 |
|
} |
655 |
|
|
656 |
/* Writes record type 7, subtypes 3 and 4. */ |
/* Writes record type 7, subtypes 3 and 4. */ |
657 |
static int |
static int |
658 |
write_rec_7_34 (struct sfm_writer *w) |
write_rec_7_34 (struct sfm_writer *w) |