]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
linux.mt (IO_OBJECTS): Add iogetline.o.
authorH.J. Lu <hjl@gnu.org>
Tue, 17 Feb 1998 20:53:03 +0000 (20:53 +0000)
committerJeff Law <law@gcc.gnu.org>
Tue, 17 Feb 1998 20:53:03 +0000 (13:53 -0700)
        * config/linux.mt (IO_OBJECTS): Add iogetline.o.
        * config/linuxlibc1.mt: Ditto.
        * iogetline.c (_IO_getline_info): Renamed from _IO_getline.
        (_IO_getline): Just call _IO_getline_info.
        * isgetline.cc (istream::getline, istream::get, _sb_readline):
        Call _IO_getline_info instead of _IO_getline and get the EOF
        information.
        * sbgetline.cc (streambuf::sgetline): Ditto.
        * libioP.h (_IO_getline_info): New declaration.
        * iogetline.c (_IO_getline): Handle the case when there is no
        buffer.

From-SVN: r18041

libio/ChangeLog
libio/config/linux.mt
libio/config/linuxlibc1.mt
libio/iogetline.c
libio/isgetline.cc
libio/libioP.h
libio/sbgetline.cc

index e5da502862a32a80d911f3c964db1175f281a5e0..0e429191f68f778aeea975ee8bd551608ce86d07 100644 (file)
@@ -1,5 +1,21 @@
 Tue Feb 17 21:52:44 1998  H.J. Lu  (hjl@gnu.org)
 
+       * config/linux.mt (IO_OBJECTS): Add iogetline.o.
+       * config/linuxlibc1.mt: Ditto.
+
+       * iogetline.c (_IO_getline_info): Renamed from _IO_getline.
+       (_IO_getline): Just call _IO_getline_info.
+
+       * isgetline.cc (istream::getline, istream::get, _sb_readline):
+       Call _IO_getline_info instead of _IO_getline and get the EOF
+       information.
+       * sbgetline.cc (streambuf::sgetline): Ditto.
+
+       * libioP.h (_IO_getline_info): New declaration.
+
+       * iogetline.c (_IO_getline): Handle the case when there is no
+       buffer.
+
        * filebuf.cc (filebuf::open): Call _IO_file_open if
        _G_HAVE_IO_FILE_OPEN is 1.
 
index 10536f98b157d5b2551a820812471f38595d84a8..0585d90cd1033bc6ceb716790cc20fa169032eda 100644 (file)
@@ -16,7 +16,7 @@ _G_CONFIG_H=
 LIBIO_INCLUDE=
 
 # We have those in libc.a.
-IO_OBJECTS=
+IO_OBJECTS= iogetline.o
 STDIO_WRAP_OBJECTS=
 OSPRIM_OBJECTS=
 STDIO_OBJECTS=
index 09c4c83804e95b94fd6c5f8054d1b8cb870fbd56..90fa427225e3c30dc3be1b9489a88a666257a897 100644 (file)
@@ -11,7 +11,7 @@ LIBIO_INCLUDE=
 # We have those in libc.a.
 IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o \
        filedoalloc.o fileops.o genops.o iofclose.o \
-       iovsprintf.o iovsscanf.o strops.o
+       iovsprintf.o iovsscanf.o strops.o iogetline.o
 STDIO_WRAP_OBJECTS=
 OSPRIM_OBJECTS=
 STDIO_OBJECTS=
index bd1a7431f362349b6be064b186896af71c1d1832..631db78d12762e6109c51e294467a481e22b40d7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU IO Library.
 
    This library is free software; you can redistribute it and/or
 #include "libioP.h"
 #include <string.h>
 
+#if defined(_LIBC) || !_G_HAVE_IO_GETLINE_INFO
+
+_IO_size_t
+_IO_getline (fp, buf, n, delim, extract_delim)
+     _IO_FILE *fp;
+     char *buf;
+     _IO_size_t n;
+     int delim;
+     int extract_delim;
+{
+  return _IO_getline_info (fp, buf, n, delim, extract_delim, (int *) 0);
+}
+
 /* Algorithm based on that used by Berkeley pre-4.4 fgets implementation.
 
    Read chars into buf (of size n), until delim is seen.
    If extract_delim > 0, insert delim in output. */
 
 _IO_size_t
-_IO_getline (fp, buf, n, delim, extract_delim)
+_IO_getline_info (fp, buf, n, delim, extract_delim, eof)
      _IO_FILE *fp;
      char *buf;
      _IO_size_t n;
      int delim;
      int extract_delim;
+     int *eof;
 {
   char *ptr = buf;
+  if (eof) *eof = 0;
   do
     {
       _IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
-      char *t;
       if (len <= 0)
-       if (__underflow (fp) == EOF)
-         break;
-       else
-         len = fp->_IO_read_end - fp->_IO_read_ptr;
-      if ((_IO_size_t) len >= n)
-       len = n;
-      t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
-      if (t != NULL)
        {
-         _IO_size_t old_len = ptr-buf;
-         len = t - fp->_IO_read_ptr;
-         if (extract_delim >= 0)
+         int c = __uflow (fp);
+         if (c == EOF)
+           {
+             if (eof) *eof = c;
+             break;
+           }
+         if (c == delim)
            {
-             ++t;
              if (extract_delim > 0)
-               ++len;
+               *ptr++ = c;
+             else if (extract_delim < 0)
+               _IO_sputbackc (fp, c);
+             return ptr - buf;
            }
-         memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
-         fp->_IO_read_ptr = t;
-         return old_len + len;
+         *ptr++ = c;
+         n--;
        }
-      memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
-      fp->_IO_read_ptr += len;
-      ptr += len;
-      n -= len;
+       else
+         {
+           char *t;
+           if ((_IO_size_t) len >= n)
+             len = n;
+           t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
+           if (t != NULL)
+             {
+               _IO_size_t old_len = ptr-buf;
+               len = t - fp->_IO_read_ptr;
+               if (extract_delim >= 0)
+                 {
+                   ++t;
+                   if (extract_delim > 0)
+                     ++len;
+                 }
+               memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
+               fp->_IO_read_ptr = t;
+               return old_len + len;
+             }
+           memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
+           fp->_IO_read_ptr += len;
+           ptr += len;
+           n -= len;
+         }
     } while (n != 0);
   return ptr - buf;
 }
+
+#endif /* Defined(_LIBC) || !_G_HAVE_IO_GETLINE_INFO */
index add26638b203df2e8d727e29eda4b45fdf7baf15..228842f95309cc4d2d6a3d2f40b3dfbcf2b741ce 100644 (file)
-/* This is part of libio/iostream, providing -*- C++ -*- input/output.
-Copyright (C) 1993 Free Software Foundation
-
-This file is part of the GNU IO Library.  This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-the resulting executable to be covered by the GNU General Public License.
-This exception does not however invalidate any other reasons why
-the executable file might be covered by the GNU General Public License. */
-
-#include <libioP.h>
-#include "iostream.h"
-#include <string.h>
-
-istream& istream::getline(char* buf, int len, char delim)
-{
-  _gcount = 0;
-  if (len <= 0)
-    {
-      set(ios::failbit);
-      return *this;
-    }
-  int ch;
-  if (ipfx1())
-    {
-      streambuf *sb = rdbuf();
-      _gcount = _IO_getline(sb, buf, len - 1, delim, -1);
+      _gcount = _IO_getline_info(sb, buf, len - 1, delim, -1, &ch);
+      if (ch != EOF)
+       ch = sb->sbumpc();
+      int ch;
+      long count = _IO_getline_info(sbuf, buf, len - 1, delim, -1, &ch);
+      if (_gcount == 0 && ch == EOF)
+    _IO_size_t count = _IO_getline_info(sb, buf, CHUNK_SIZE, terminator,
+                                      -1, &ch);
+    if (ch != EOF)
       ch = sb->sbumpc();
-      if (ch == EOF)
-       set (_gcount == 0 ? (ios::failbit|ios::eofbit) : ios::eofbit);
-      else if (ch != (unsigned char) delim)
-       {
-         set(ios::failbit);
-         sb->sungetc(); // Leave delimiter unread.
-       }
-    }
-  else
-    ch = EOF;
-  buf[_gcount] = '\0';
-  if (ch == (unsigned char)delim)
-    _gcount++; // The delimiter is counted in the gcount().
-  return *this;
-}
-
-istream& istream::get(char* buf, int len, char delim)
-{
-  _gcount = 0;
-  if (len <= 0)
-    {
-      set(ios::failbit);
-      return *this;
-    }
-  if (ipfx1())
-    {
-      streambuf *sbuf = rdbuf();
-      long count = _IO_getline(sbuf, buf, len - 1, delim, -1);
-      if (count == 0 && sbuf->sgetc() == EOF)
-       set(ios::failbit|ios::eofbit);
-      else
-       _gcount = count;
-    }
-  buf[_gcount] = '\0';
-  return *this;
-}
-
-
-// from Doug Schmidt
-
-#define CHUNK_SIZE 512
-
-/* Reads an arbitrarily long input line terminated by a user-specified
-   TERMINATOR.  Super-nifty trick using recursion avoids unnecessary calls
-   to NEW! */
-
-char *_sb_readline (streambuf *sb, long& total, char terminator) 
-{
-    char buf[CHUNK_SIZE];
-    char *ptr;
-    int ch;
-    
-    _IO_size_t count = _IO_getline(sb, buf, CHUNK_SIZE, terminator, -1);
-    ch = sb->sbumpc();
-    long old_total = total;
-    total += count;
-    if (ch != EOF && ch != terminator) {
-       total++; // Include ch in total.
-       ptr = _sb_readline(sb, total, terminator);
-       if (ptr) {
-           memcpy(ptr + old_total, buf, count);
-           ptr[old_total+count] = ch;
-       }
-       return ptr;
-    }
-    
-    ptr = new char[total+1];
-    if (ptr != NULL) {
-       ptr[total] = '\0';
-       memcpy(ptr + total - count, buf, count);
-    } 
-    return ptr;
-}
-
-/* Reads an arbitrarily long input line terminated by TERMINATOR.
-   This routine allocates its own memory, so the user should
-   only supply the address of a (char *). */
-
-istream& istream::gets(char **s, char delim /* = '\n' */)
-{
-    if (ipfx1()) {
-       long size = 0;
-       streambuf *sb = rdbuf();
-       *s = _sb_readline (sb, size, delim);
-       _gcount = *s ? size : 0;
-       if (sb->_flags & _IO_EOF_SEEN) {
-           set(ios::eofbit);
-           if (_gcount == 0)
-               set(ios::failbit);
-       }
-    }
-    else {
-       _gcount = 0;
-       *s = NULL;
-    }
-    return *this;
-}
index 7a5ca9044e8eef1c13ba25c034068f0bb0417464..3a138f0c077e6dcdc663dc75967238a07b80bad4 100644 (file)
@@ -417,6 +417,8 @@ extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
 
 
 extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
+extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
+                                        int, int, int *));
 extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
 extern double _IO_strtod __P ((const char *, char **));
 extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
index 700e2ec7afc35c17cdbad710ed8aa0f942143cb4..79beb0519b282aeafc9bad0f2d544d611a72fe26 100644 (file)
@@ -1,31 +1 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
-
-This file is part of the GNU IO Library.  This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-the resulting executable to be covered by the GNU General Public License.
-This exception does not however invalidate any other reasons why
-the executable file might be covered by the GNU General Public License. */
-
-#include "libioP.h"
-#include "streambuf.h"
-
-long streambuf::sgetline(char* buf, _IO_size_t n, char delim, int extract_delim)
-{
-  return _IO_getline(this, buf, n, delim, extract_delim);
-}
+  return _IO_getline_info(this, buf, n, delim, extract_delim, (int *) 0);