pspp-cvs
[Top][All Lists]
Advanced

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

[Pspp-cvs] pspp/src/language/data-io ChangeLog placement-p...


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src/language/data-io ChangeLog placement-p...
Date: Wed, 05 Dec 2007 06:24:46 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 07/12/05 06:24:46

Modified files:
        src/language/data-io: ChangeLog placement-parser.c 
                              placement-parser.h print.c 

Log message:
        Allow parsing 0-based column ranges.
        
        (parse_column): New function.
        (parse_column_range): Add `base' argument.  Update all callers.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/ChangeLog?cvsroot=pspp&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/placement-parser.c?cvsroot=pspp&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/placement-parser.h?cvsroot=pspp&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/print.c?cvsroot=pspp&r1=1.31&r2=1.32

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/ChangeLog,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- ChangeLog   5 Dec 2007 06:22:46 -0000       1.53
+++ ChangeLog   5 Dec 2007 06:24:46 -0000       1.54
@@ -1,5 +1,10 @@
 2007-12-04  Ben Pfaff  <address@hidden>
 
+       * placement-parser.c (parse_column): New function.
+       (parse_column_range): Add `base' argument.  Update all callers.
+       
+2007-12-04  Ben Pfaff  <address@hidden>
+
        Make GET DATA a separate command, instead of something invoked
        indirectly from GET.
 

Index: placement-parser.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/placement-parser.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- placement-parser.c  13 Oct 2007 04:35:26 -0000      1.8
+++ placement-parser.c  5 Dec 2007 06:24:46 -0000       1.9
@@ -107,7 +107,7 @@
   int fc, lc;
   size_t i;
 
-  if ( !parse_column_range (lexer, &fc, &lc, NULL) )
+  if ( !parse_column_range (lexer, 1, &fc, &lc, NULL) )
     return false;
 
   /* Divide columns evenly. */
@@ -287,42 +287,57 @@
     }
 }
 
+/* Parses a BASE-based column using LEXER.  Returns true and
+   stores a 1-based column number into *COLUMN if successful,
+   otherwise emits an error message and returns false. */
+static bool
+parse_column (struct lexer *lexer, int base, int *column)
+{
+  assert (base == 0 || base == 1);
+  if (!lex_force_int (lexer))
+    return false;
+  *column = lex_integer (lexer) - base + 1;
+  if (*column < 1)
+    {
+      if (base == 1)
+        msg (SE, _("Column positions for fields must be positive."));
+      else
+        msg (SE, _("Column positions for fields must not be negative."));
+      return false;
+    }
+  lex_get (lexer);
+  return true;
+}
+
 /* Parse a column or a range of columns, specified as a single
-   integer or two integer delimited by a dash.  Stores the range
+   integer or two integers delimited by a dash.  Stores the range
    in *FIRST_COLUMN and *LAST_COLUMN.  (If only a single integer
    is given, it is stored in both.)  If RANGE_SPECIFIED is
    non-null, then *RANGE_SPECIFIED is set to true if the syntax
    contained a dash, false otherwise.  Returns true if
    successful, false if the syntax was invalid or the values
-   specified did not make sense. */
+   specified did not make sense.
+
+   If BASE is 0, zero-based column numbers are parsed; if BASE is
+   1, 1-based column numbers are parsed.  Regardless of BASE, the
+   values stored in *FIRST_COLUMN and *LAST_COLUMN are
+   1-based. */
 bool
-parse_column_range (struct lexer *lexer, int *first_column, int *last_column,
+parse_column_range (struct lexer *lexer, int base,
+                    int *first_column, int *last_column,
                     bool *range_specified)
 {
   /* First column. */
-  if (!lex_force_int (lexer))
+  if (!parse_column (lexer, base, first_column))
     return false;
-  *first_column = lex_integer (lexer);
-  if (*first_column < 1)
-    {
-      msg (SE, _("Column positions for fields must be positive."));
-      return false;
-    }
-  lex_get (lexer);
 
   /* Last column. */
   lex_negative_to_dash (lexer);
   if (lex_match (lexer, '-'))
     {
-      if (!lex_force_int (lexer))
-       return false;
-      *last_column = lex_integer (lexer);
-      if (*last_column < 1)
-       {
-         msg (SE, _("Column positions for fields must be positive."));
+      if (!parse_column (lexer, base, last_column))
          return false;
-       }
-      else if (*last_column < *first_column)
+      if (*last_column < *first_column)
        {
          msg (SE, _("The ending column for a field must be "
                     "greater than the starting column."));
@@ -331,7 +346,6 @@
 
       if (range_specified)
         *range_specified = true;
-      lex_get (lexer);
     }
   else
     {

Index: placement-parser.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/placement-parser.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- placement-parser.h  7 Jul 2007 06:14:13 -0000       1.5
+++ placement-parser.h  5 Dec 2007 06:24:46 -0000       1.6
@@ -29,7 +29,8 @@
                            struct fmt_spec **, size_t *format_cnt);
 bool execute_placement_format (const struct fmt_spec *,
                                int *record, int *column);
-bool parse_column_range (struct lexer *, int *first_column, int *last_column,
+bool parse_column_range (struct lexer *, int base,
+                         int *first_column, int *last_column,
                          bool *range_specified);
 
 #endif /* language/data-io/placement-parser.h */

Index: print.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/print.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- print.c     9 Nov 2007 03:06:29 -0000       1.31
+++ print.c     5 Dec 2007 06:24:46 -0000       1.32
@@ -288,7 +288,8 @@
       int first_column, last_column;
       bool range_specified;
 
-      if (!parse_column_range (lexer, &first_column, &last_column, 
&range_specified))
+      if (!parse_column_range (lexer, 1,
+                               &first_column, &last_column, &range_specified))
         return false;
 
       spec->first_column = first_column;




reply via email to

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