[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src ui/terminal/read-line.c libpspp/str.h ...
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp/src ui/terminal/read-line.c libpspp/str.h ... |
Date: |
Tue, 19 Feb 2008 06:45:13 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Changes by: Ben Pfaff <blp> 08/02/19 06:45:13
Modified files:
src/ui/terminal: read-line.c
src/libpspp : str.h str.c ChangeLog
src/language/data-io: data-reader.c
src/language : syntax-file.c
Log message:
(ds_read_line): Add argument to limit the length of the line to be
read. Update all callers.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/ui/terminal/read-line.c?cvsroot=pspp&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/str.h?cvsroot=pspp&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/str.c?cvsroot=pspp&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/ChangeLog?cvsroot=pspp&r1=1.87&r2=1.88
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/data-reader.c?cvsroot=pspp&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/syntax-file.c?cvsroot=pspp&r1=1.8&r2=1.9
Patches:
Index: ui/terminal/read-line.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/ui/terminal/read-line.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- ui/terminal/read-line.c 19 Jan 2008 06:58:07 -0000 1.20
+++ ui/terminal/read-line.c 19 Feb 2008 06:45:11 -0000 1.21
@@ -173,7 +173,7 @@
#else
fputs (prompt, stdout);
fflush (stdout);
- if (ds_read_line (line, stdin))
+ if (ds_read_line (line, stdin, SIZE_MAX))
{
ds_chomp (line, '\n');
eof = false;
Index: libpspp/str.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/str.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- libpspp/str.h 2 Feb 2008 06:58:13 -0000 1.24
+++ libpspp/str.h 19 Feb 2008 06:45:12 -0000 1.25
@@ -202,7 +202,7 @@
char *ds_cstr (const struct string *);
/* File input. */
-bool ds_read_line (struct string *, FILE *);
+bool ds_read_line (struct string *, FILE *, size_t max_length);
bool ds_read_config_line (struct string *, int *line_number, FILE *);
bool ds_read_stream (struct string *, size_t size, size_t cnt, FILE *stream);
Index: libpspp/str.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/str.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- libpspp/str.c 2 Feb 2008 06:58:13 -0000 1.26
+++ libpspp/str.c 19 Feb 2008 06:45:12 -0000 1.27
@@ -1170,30 +1170,47 @@
return st->ss.string;
}
-/* Appends to ST a newline-terminated line read from STREAM.
- Newline is the last character of ST on return, unless an I/O error
- or end of file is encountered after reading some characters.
- Returns true if a line is successfully read, false if no characters at
- all were read before an I/O error or end of file was
- encountered. */
+/* Appends to ST a newline-terminated line read from STREAM, but
+ no more than MAX_LENGTH characters.
+ Newline is the last character of ST on return, if encountering
+ a newline was the reason for terminating.
+ Returns true if at least one character was read from STREAM
+ and appended to ST, false if no characters at all were read
+ before an I/O error or end of file was encountered (or
+ MAX_LENGTH was 0). */
bool
-ds_read_line (struct string *st, FILE *stream)
+ds_read_line (struct string *st, FILE *stream, size_t max_length)
{
- int c;
-
- c = getc (stream);
- if (c == EOF)
+ if (!st->ss.length && max_length == SIZE_MAX)
+ {
+ size_t capacity = st->capacity ? st->capacity + 1 : 0;
+ ssize_t n = getline (&st->ss.string, &capacity, stream);
+ if (capacity)
+ st->capacity = capacity - 1;
+ if (n > 0)
+ {
+ st->ss.length = n;
+ return true;
+ }
+ else
return false;
+ }
+ else
+ {
+ size_t length;
- for (;;)
+ for (length = 0; length < max_length; length++)
{
+ int c = getc (stream);
+ if (c == EOF)
+ break;
+
ds_put_char (st, c);
if (c == '\n')
return true;
+ }
- c = getc (stream);
- if (c == EOF)
- return true;
+ return length > 0;
}
}
@@ -1240,7 +1257,7 @@
ds_clear (st);
do
{
- if (!ds_read_line (st, stream))
+ if (!ds_read_line (st, stream, SIZE_MAX))
return false;
(*line_number)++;
ds_rtrim (st, ss_cstr (CC_SPACES));
Index: libpspp/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/ChangeLog,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -b -r1.87 -r1.88
--- libpspp/ChangeLog 2 Feb 2008 06:58:13 -0000 1.87
+++ libpspp/ChangeLog 19 Feb 2008 06:45:12 -0000 1.88
@@ -1,3 +1,10 @@
+2008-02-18 Ben Pfaff <address@hidden>
+
+ Patch #6426. Thanks to John Darrington for review.
+
+ * str.c (ds_read_line): Add argument to limit the length of the
+ line to be read. Update all callers.
+
2008-02-01 Ben Pfaff <address@hidden>
Patch #6386. Thanks to John Darrington for review.
Index: language/data-io/data-reader.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/data-reader.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- language/data-io/data-reader.c 5 Dec 2007 06:04:59 -0000 1.30
+++ language/data-io/data-reader.c 19 Feb 2008 06:45:12 -0000 1.31
@@ -340,7 +340,7 @@
switch (fh_get_mode (r->fh))
{
case FH_MODE_TEXT:
- if (ds_read_line (&r->line, r->file))
+ if (ds_read_line (&r->line, r->file, SIZE_MAX))
{
ds_chomp (&r->line, '\n');
return true;
Index: language/syntax-file.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/syntax-file.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- language/syntax-file.c 19 Jan 2008 06:58:05 -0000 1.8
+++ language/syntax-file.c 19 Feb 2008 06:45:13 -0000 1.9
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <errno.h>
+#include <stdint.h>
#include <stdlib.h>
#include <data/file-name.h>
@@ -99,7 +100,7 @@
do
{
sfs->ln++;
- if (!ds_read_line (line, sfs->syntax_file))
+ if (!ds_read_line (line, sfs->syntax_file, SIZE_MAX))
{
if (ferror (sfs->syntax_file))
msg (ME, _("Reading `%s': %s."), sfs->fn, strerror (errno));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] pspp/src ui/terminal/read-line.c libpspp/str.h ...,
Ben Pfaff <=