pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src/data ChangeLog por-file-writer.c


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src/data ChangeLog por-file-writer.c
Date: Mon, 23 Jul 2007 05:11:59 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 07/07/23 05:11:59

Modified files:
        src/data       : ChangeLog por-file-writer.c 

Log message:
        Don't try to write very long strings to portable files.  The format
        does not support it.
        
        (MAX_POR_WIDTH): New macro.
        (pfm_open_writer): Limit output width to MAX_POR_WIDTH.
        (write_format): Add arg to take width to resize format to.
        (write_value): Limit width of value written to MAX_POR_WIDTH.
        (write_variables): Limit width of variable and its output formats
        to MAX_POR_WIDTH.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.138&r2=1.139
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/por-file-writer.c?cvsroot=pspp&r1=1.13&r2=1.14

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -b -r1.138 -r1.139
--- ChangeLog   23 Jul 2007 05:07:23 -0000      1.138
+++ ChangeLog   23 Jul 2007 05:11:58 -0000      1.139
@@ -1,5 +1,17 @@
 2007-07-22  Ben Pfaff  <address@hidden>
 
+       Don't try to write very long strings to portable files.  The
+       format does not support it.
+
+       * por-file-writer.c (MAX_POR_WIDTH): New macro.
+       (pfm_open_writer): Limit output width to MAX_POR_WIDTH.
+       (write_format): Add arg to take width to resize format to.
+       (write_value): Limit width of value written to MAX_POR_WIDTH.
+       (write_variables): Limit width of variable and its output formats
+       to MAX_POR_WIDTH.
+
+2007-07-22  Ben Pfaff  <address@hidden>
+
        * sys-file-reader.c (read_variable_to_value_map): Use max_warnings
        local variable instead of literal 5.
        

Index: por-file-writer.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/por-file-writer.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- por-file-writer.c   23 Jul 2007 05:05:45 -0000      1.13
+++ por-file-writer.c   23 Jul 2007 05:11:58 -0000      1.14
@@ -50,6 +50,9 @@
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
+/* Maximum width of a variable in a portable file. */
+#define MAX_POR_WIDTH 255
+
 /* Portable file writer. */
 struct pfm_writer
   {
@@ -139,7 +142,7 @@
     {
       const struct variable *dv = dict_get_var (dict, i);
       struct pfm_var *pv = &w->vars[i];
-      pv->width = var_get_width (dv);
+      pv->width = MIN (var_get_width (dv), MAX_POR_WIDTH);
       pv->fv = var_get_case_index (dv);
     }
 
@@ -284,13 +287,17 @@
   write_string (w, host_system);
 }
 
-/* Write format F to file H. */
-static void
-write_format (struct pfm_writer *w, const struct fmt_spec *f)
-{
-  write_int (w, fmt_to_io (f->type));
-  write_int (w, f->w);
-  write_int (w, f->d);
+/* Write format F to file H.  The format is first resized to fit
+   a value of the given WIDTH, which is handy in case F
+   represents a string longer than 255 bytes and thus WIDTH is
+   truncated to 255 bytes.  */
+static void
+write_format (struct pfm_writer *w, struct fmt_spec f, int width)
+{
+  fmt_resize (&f, width);
+  write_int (w, fmt_to_io (f.type));
+  write_int (w, f.w);
+  write_int (w, f.d);
 }
 
 /* Write value V for variable VV to file H. */
@@ -301,8 +308,9 @@
     write_float (w, v->f);
   else
     {
-      write_int (w, var_get_width (vv));
-      buf_write (w, v->s, var_get_width (vv));
+      int width = MIN (var_get_width (vv), MAX_POR_WIDTH);
+      write_int (w, width);
+      buf_write (w, v->s, width);
     }
 }
 
@@ -322,12 +330,13 @@
     {
       struct variable *v = dict_get_var (dict, i);
       struct missing_values mv;
+      int width = MIN (var_get_width (v), MAX_POR_WIDTH);
 
       buf_write (w, "7", 1);
-      write_int (w, var_get_width (v));
+      write_int (w, width);
       write_string (w, var_get_short_name (v, 0));
-      write_format (w, var_get_print_format (v));
-      write_format (w, var_get_write_format (v));
+      write_format (w, *var_get_print_format (v), width);
+      write_format (w, *var_get_write_format (v), width);
 
       /* Write missing values. */
       mv_copy (&mv, var_get_missing_values (v));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]