[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src/data ChangeLog format.c format.h
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp/src/data ChangeLog format.c format.h |
Date: |
Wed, 05 Mar 2008 05:53:46 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Changes by: Ben Pfaff <blp> 08/03/05 05:53:46
Modified files:
src/data : ChangeLog format.c format.h
Log message:
Patch #6441. Reviewed by John Darrington.
(fmt_fix): New function.
(fmt_fix_input): New function.
(fmt_fix_output): New function.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.188&r2=1.189
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/format.c?cvsroot=pspp&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/format.h?cvsroot=pspp&r1=1.20&r2=1.21
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.188
retrieving revision 1.189
diff -u -b -r1.188 -r1.189
--- ChangeLog 19 Feb 2008 06:41:25 -0000 1.188
+++ ChangeLog 5 Mar 2008 05:53:46 -0000 1.189
@@ -1,3 +1,11 @@
+2008-03-04 Ben Pfaff <address@hidden>
+
+ Patch #6441. Reviewed by John Darrington.
+
+ * format.c (fmt_fix): New function.
+ (fmt_fix_input): New function.
+ (fmt_fix_output): New function.
+
2008-02-18 Ben Pfaff <address@hidden>
Patch #6426. Reviewed by John Darrington.
Index: format.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/format.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- format.c 19 Feb 2008 06:32:18 -0000 1.25
+++ format.c 5 Mar 2008 05:53:46 -0000 1.26
@@ -409,6 +409,61 @@
}
}
+/* Adjusts FMT's width and decimal places to be valid for an
+ input format (if FOR_INPUT) or an output format (if
+ !FOR_INPUT). */
+void
+fmt_fix (struct fmt_spec *fmt, bool for_input)
+{
+ int min_w, max_w;
+ int max_d;
+
+ /* Clamp width to those allowed by format. */
+ min_w = fmt_min_width (fmt->type, for_input);
+ max_w = fmt_max_width (fmt->type, for_input);
+ if (fmt->w < min_w)
+ fmt->w = min_w;
+ else if (fmt->w > max_w)
+ fmt->w = max_w;
+
+ /* First, if FMT has more decimal places than allowed, attempt
+ to increase FMT's width until that number of decimal places
+ can be achieved. */
+ if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input))
+ {
+ int w;
+ for (w = fmt->w; w <= max_w; w++)
+ if (fmt_max_decimals (fmt->type, w, for_input) >= fmt->d)
+ {
+ fmt->w = w;
+ break;
+ }
+ }
+
+ /* Clamp decimals to those allowed by format and width. */
+ max_d = fmt_max_decimals (fmt->type, fmt->w, for_input);
+ if (fmt->d < 0)
+ fmt->d = 0;
+ else if (fmt->d > max_d)
+ fmt->d = max_d;
+}
+
+/* Adjusts FMT's width and decimal places to be valid for an
+ input format. */
+void
+fmt_fix_input (struct fmt_spec *fmt)
+{
+ fmt_fix (fmt, true);
+}
+
+/* Adjusts FMT's width and decimal places to be valid for an
+ output format. */
+void
+fmt_fix_output (struct fmt_spec *fmt)
+{
+ fmt_fix (fmt, false);
+}
+
/* Describes a display format. */
struct fmt_desc
{
Index: format.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/format.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- format.h 19 Feb 2008 06:37:57 -0000 1.20
+++ format.h 5 Mar 2008 05:53:46 -0000 1.21
@@ -110,6 +110,10 @@
bool fmt_equal (const struct fmt_spec *, const struct fmt_spec *);
void fmt_resize (struct fmt_spec *, int new_width);
+void fmt_fix (struct fmt_spec *, bool for_input);
+void fmt_fix_input (struct fmt_spec *);
+void fmt_fix_output (struct fmt_spec *);
+
/* Format types. */
const char *fmt_name (enum fmt_type) PURE_FUNCTION;
bool fmt_from_name (const char *name, enum fmt_type *);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] pspp/src/data ChangeLog format.c format.h,
Ben Pfaff <=