/[pspp]/pspp/src/sfm-write.c
ViewVC logotype

Diff of /pspp/src/sfm-write.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by jmd, Fri Apr 29 01:02:15 2005 UTC revision 1.16 by blp, Mon May 2 06:21:20 2005 UTC
# Line 106  var_flt64_cnt (const struct variable *v) Line 106  var_flt64_cnt (const struct variable *v)
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. If  OMIT_LONGNAMES is nonzero, the     system file will be compressed.  If OMIT_LONG_NAMES is nonzero, the
110     long name table will be omitted.     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.  D is not
114       modified by this function, except to assign short names. */
115  struct sfm_writer *  struct sfm_writer *
116  sfm_open_writer (struct file_handle *fh,  sfm_open_writer (struct file_handle *fh,
117                   const struct dictionary *d, int compress,                   struct dictionary *d, int compress,
118                   short omit_longnames)                   short omit_long_names)
119  {  {
120    struct sfm_writer *w = NULL;    struct sfm_writer *w = NULL;
121    int idx;    int idx;
# Line 162  sfm_open_writer (struct file_handle *fh, Line 163  sfm_open_writer (struct file_handle *fh,
163      goto error;      goto error;
164    
165    /* Write basic variable info. */    /* Write basic variable info. */
166      dict_assign_short_names (d);
167    for (i = 0; i < dict_get_var_cnt (d); i++)    for (i = 0; i < dict_get_var_cnt (d); i++)
168      write_variable (w, dict_get_var (d, i));      write_variable (w, dict_get_var (d, i));
169    
# Line 181  sfm_open_writer (struct file_handle *fh, Line 183  sfm_open_writer (struct file_handle *fh,
183    if (!write_rec_7_34 (w))    if (!write_rec_7_34 (w))
184      goto error;      goto error;
185    
186      if (!write_variable_display_parameters (w, d))
   /* Write  variable display info. */  
   if ( !write_variable_display_parameters(w, d))  
187      goto error;      goto error;
188    
189        if (!omit_long_names)
   if ( ! omit_longnames )  
190      {      {
191        if (!write_longvar_table (w, d))        if (!write_longvar_table (w, d))
192          goto error;          goto error;
193      }      }
194    
195    /* Write record 999. */    /* Write end-of-headers record. */
196    {    {
197      struct      struct
198        {        {
# Line 419  write_variable (struct sfm_writer *w, st Line 418  write_variable (struct sfm_writer *w, st
418    sv.n_missing_values = nm;    sv.n_missing_values = nm;
419    write_format_spec (&v->print, &sv.print);    write_format_spec (&v->print, &sv.print);
420    write_format_spec (&v->write, &sv.write);    write_format_spec (&v->write, &sv.write);
421    memcpy (sv.name, v->name, strlen (v->name));    st_bare_pad_copy (sv.name, v->short_name, sizeof sv.name);
   memset (&sv.name[strlen (v->name)], ' ', SHORT_NAME_LEN - strlen (v->name));  
422    if (!buf_write (w, &sv, sizeof sv))    if (!buf_write (w, &sv, sizeof sv))
423      return 0;      return 0;
424    
# Line 617  write_variable_display_parameters (struc Line 615  write_variable_display_parameters (struc
615  static int  static int
616  write_longvar_table (struct sfm_writer *w, const struct dictionary *dict)  write_longvar_table (struct sfm_writer *w, const struct dictionary *dict)
617  {  {
   char *buf = 0;  
   int bufsize = 0;  
   
618    struct    struct
619    {      {
620      int32 rec_type P;        int32 rec_type P;
621      int32 subtype P;        int32 subtype P;
622      int32 elem_size P;        int32 elem_size P;
623      int32 n_elem P;        int32 n_elem P;
624    } lv_hdr;      }
625      lv_hdr;
626    
627      struct string long_name_map;
628      size_t i;
629    
630      ds_init (&long_name_map, 10 * dict_get_var_cnt (dict));
631      for (i = 0; i < dict_get_var_cnt (dict); i++)
632        {
633          struct variable *v = dict_get_var (dict, i);
634          
635          if (i)
636            ds_putc (&long_name_map, '\t');
637          ds_printf (&long_name_map, "%s=%s", v->short_name, v->name);
638        }
639    
640    lv_hdr.rec_type = 7;    lv_hdr.rec_type = 7;
641    lv_hdr.subtype = 13;    lv_hdr.subtype = 13;
642    lv_hdr.elem_size = 1;    lv_hdr.elem_size = 1;
643      lv_hdr.n_elem = ds_length (&long_name_map);
644    
645      if (!buf_write (w, &lv_hdr, sizeof lv_hdr)
646    dict_get_varname_block(dict, &buf, &bufsize);        || !buf_write (w, ds_data (&long_name_map), ds_length (&long_name_map)))
   
   if ( bufsize == 0 )  
     return 1;  
   
   lv_hdr.n_elem = bufsize ;  
   
   if (!buf_write (w, &lv_hdr, sizeof(lv_hdr) ))  
     goto error;  
   
   if (!buf_write (w, buf, bufsize))  
647      goto error;      goto error;
648    
649    free (buf);    ds_destroy (&long_name_map);
650    return 1;    return 1;
651    
652   error:   error:
653    free ( buf ) ;    ds_destroy (&long_name_map);
654    return 0;    return 0;
655  }  }
656    

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26