Mercurial > hg > octave-kai > gnulib-hg
changeset 4463:7564fca8961e
New module 'getndelim2'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 18 Jul 2003 16:58:06 +0000 |
parents | fd8a264f27f2 |
children | 580114b1a865 |
files | ChangeLog MODULES.html.sh lib/ChangeLog lib/getline.c lib/getline.h lib/getndelim2.c lib/getndelim2.h lib/getnline.c m4/ChangeLog m4/getline.m4 m4/getndelim2.m4 m4/getnline.m4 modules/getline modules/getndelim2 modules/getnline |
diffstat | 15 files changed, 152 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-07-18 Bruno Haible <bruno@clisp.org> + + * modules/getndelim2: New file. + * modules/getline: Share files with module getndelim2. + * modules/getnline: Depend on getndelim2 instead of sharing files with + it. Add getnline.c to lib_SOURCES. + * MODULES.html.sh (func_all_modules): Add getndelim2. + 2003-07-17 Bruno Haible <bruno@clisp.org> * modules/getnline: New file.
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1580,6 +1580,7 @@ func_module diacrit func_module getline func_module getnline + func_module getndelim2 func_module linebuffer func_module obstack func_module hash-pjw
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2003-07-18 Bruno Haible <bruno@clisp.org> + + * getndelim2.h: New file. + * getndelim2.c: Make into a module of its own. Include config.h, + getndelim2.h. + (getndelim2): Make non-static. Change return type to ssize_t. + * getline.h: Change argument names. + * getline.c: Include getndelim2.h instead of getndelim2.c. + * getnline.c: Include getndelim2.h. + 2003-07-17 Bruno Haible <bruno@clisp.org> * Makefile.am: Remove file.
--- a/lib/getline.c +++ b/lib/getline.c @@ -38,24 +38,24 @@ #if defined __GNU_LIBRARY__ && HAVE_GETDELIM int -getline (char **lineptr, size_t *n, FILE *stream) +getline (char **lineptr, size_t *linesize, FILE *stream) { - return getdelim (lineptr, n, '\n', stream); + return getdelim (lineptr, linesize, '\n', stream); } #else /* ! have getdelim */ -#include "getndelim2.c" +#include "getndelim2.h" int -getline (char **lineptr, size_t *n, FILE *stream) +getline (char **lineptr, size_t *linesize, FILE *stream) { - return getndelim2 (lineptr, n, (size_t)(-1), stream, '\n', 0, 0); + return getndelim2 (lineptr, linesize, (size_t)(-1), stream, '\n', 0, 0); } int -getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream) +getdelim (char **lineptr, size_t *linesize, int delimiter, FILE *stream) { - return getndelim2 (lineptr, n, (size_t)(-1), stream, delimiter, 0, 0); + return getndelim2 (lineptr, linesize, (size_t)(-1), stream, delimiter, 0, 0); } #endif
--- a/lib/getline.h +++ b/lib/getline.h @@ -26,9 +26,10 @@ /* glibc2 has these functions declared in <stdio.h>. Avoid redeclarations. */ # if __GLIBC__ < 2 -int getline (char **_lineptr, size_t *_n, FILE *_stream); +extern int getline (char **_lineptr, size_t *_linesize, FILE *_stream); -int getdelim (char **_lineptr, size_t *_n, int _delimiter, FILE *_stream); +extern int getdelim (char **_lineptr, size_t *_linesize, int _delimiter, + FILE *_stream); # endif
--- a/lib/getndelim2.c +++ b/lib/getndelim2.c @@ -1,4 +1,5 @@ -/* getndelim2 - Core of getline, getdelim, getnline, getndelim. +/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters, + with bounded memory allocation. Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003 Free Software Foundation, Inc. @@ -17,6 +18,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* Originally written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include "getndelim2.h" + #if STDC_HEADERS # include <stdlib.h> #else @@ -28,17 +38,7 @@ /* Always add at least this many bytes when extending the buffer. */ #define MIN_CHUNK 64 -/* Read up to (and including) a delimiter DELIM1 from STREAM into *LINEPTR - + OFFSET (and NUL-terminate it). If DELIM2 is non-zero, then read up - and including the first occurrence of DELIM1 or DELIM2. *LINEPTR is - a pointer returned from malloc (or NULL), pointing to *LINESIZE bytes of - space. It is realloc'd as necessary. Reallocation is limited to - NMAX bytes; if the line is longer than that, the extra bytes are read but - thrown away. - Return the number of bytes read and stored at *LINEPTR + OFFSET (not - including the NUL terminator), or -1 on error or EOF. */ - -static int +ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t nmax, FILE *stream, int delim1, int delim2, size_t offset) {
new file mode 100644 --- /dev/null +++ b/lib/getndelim2.h @@ -0,0 +1,42 @@ +/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters, + with bounded memory allocation. + + Copyright (C) 2003 Free Software Foundation, Inc. + + This program 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 program 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 program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef GETNDELIM2_H +#define GETNDELIM2_H 1 + +#include <stddef.h> +#include <stdio.h> + +/* Get ssize_t. */ +#include <sys/types.h> + +/* Read up to (and including) a delimiter DELIM1 from STREAM into *LINEPTR + + OFFSET (and NUL-terminate it). If DELIM2 is non-zero, then read up + and including the first occurrence of DELIM1 or DELIM2. *LINEPTR is + a pointer returned from malloc (or NULL), pointing to *LINESIZE bytes of + space. It is realloc'd as necessary. Reallocation is limited to + NMAX bytes; if the line is longer than that, the extra bytes are read but + thrown away. + Return the number of bytes read and stored at *LINEPTR + OFFSET (not + including the NUL terminator), or -1 on error or EOF. */ +extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t nmax, + FILE *stream, int delim1, int delim2, + size_t offset); + +#endif /* GETNDELIM2_H */
--- a/lib/getnline.c +++ b/lib/getnline.c @@ -23,6 +23,8 @@ /* Specification. */ #include "getnline.h" +#include "getndelim2.h" + ssize_t getnline (char **lineptr, size_t *linesize, size_t nmax, FILE *stream) {
--- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,13 @@ +2003-07-18 Bruno Haible <bruno@clisp.org> + + * getndelim2.m4: New file. + * getline.m4 (AM_FUNC_GETLINE): Add AC_LIBOBJ of getndelim2.c and + invoke gl_PREREQ_GETNDELIM2. + (gl_PREREQ_GETLINE): Drop AC_HEADER_STDC, now done by + gl_PREREQ_GETNDELIM2. + * getnline.m4 (gl_GETNLINE): Drop AC_HEADER_STDC, now done by + gl_GETNDELIM2. + 2003-07-17 Bruno Haible <bruno@clisp.org> * Makefile.am.in: Remove file.
--- a/m4/getline.m4 +++ b/m4/getline.m4 @@ -1,4 +1,4 @@ -# getline.m4 serial 8 +# getline.m4 serial 9 dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software dnl Foundation, Inc. @@ -56,13 +56,14 @@ AC_DEFINE([getline], [gnu_getline], [Define to a replacement function name for getline().]) AC_LIBOBJ(getline) + AC_LIBOBJ(getndelim2) gl_PREREQ_GETLINE + gl_PREREQ_GETNDELIM2 fi ]) # Prerequisites of lib/getline.c. AC_DEFUN([gl_PREREQ_GETLINE], [ - AC_REQUIRE([AC_HEADER_STDC]) AC_CHECK_FUNCS(getdelim) ])
new file mode 100644 --- /dev/null +++ b/m4/getndelim2.m4 @@ -0,0 +1,21 @@ +# getndelim2.m4 serial 1 +dnl Copyright (C) 2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +AC_DEFUN([gl_GETNDELIM2], +[ + gl_PREREQ_GETNDELIM2 +]) + +# Prerequisites of lib/getndelim2.h and lib/getndelim2.c. +AC_DEFUN([gl_PREREQ_GETNDELIM2], +[ + dnl Prerequisites of lib/getndelim2.h. + AC_REQUIRE([gt_TYPE_SSIZE_T]) + dnl Prerequisites of lib/getndelim2.c. + AC_REQUIRE([AC_HEADER_STDC]) +])
--- a/m4/getnline.m4 +++ b/m4/getnline.m4 @@ -1,4 +1,4 @@ -# getnline.m4 serial 1 +# getnline.m4 serial 2 dnl Copyright (C) 2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -11,5 +11,5 @@ dnl Prerequisites of lib/getnline.h. AC_REQUIRE([gt_TYPE_SSIZE_T]) dnl Prerequisites of lib/getnline.c. - AC_REQUIRE([AC_HEADER_STDC]) + : ])
--- a/modules/getline +++ b/modules/getline @@ -4,8 +4,11 @@ Files: lib/getline.h lib/getline.c +lib/getndelim2.h lib/getndelim2.c m4/getline.m4 +m4/getndelim2.m4 +m4/ssize_t.m4 Depends-on: unlocked-io @@ -15,7 +18,7 @@ Makefile.am: lib_SOURCES += getline.h -EXTRA_DIST += getndelim2.c +EXTRA_DIST += getndelim2.h getndelim2.c Include: "getline.h"
new file mode 100644 --- /dev/null +++ b/modules/getndelim2 @@ -0,0 +1,25 @@ +Description: +Read a line from a stream, stopping at one of 2 delimiters, with bounded +memory allocation. + +Files: +lib/getndelim2.h +lib/getndelim2.c +m4/getndelim2.m4 +m4/ssize_t.m4 + +Depends-on: +unlocked-io + +configure.ac: +gl_GETNDELIM2 + +Makefile.am: +lib_SOURCES += getndelim2.h getndelim2.c + +Include: +"getndelim2.h" + +Maintainer: +all +
--- a/modules/getnline +++ b/modules/getnline @@ -4,19 +4,17 @@ Files: lib/getnline.h lib/getnline.c -lib/getndelim2.c m4/getnline.m4 m4/ssize_t.m4 Depends-on: -unlocked-io +getndelim2 configure.ac: gl_GETNLINE Makefile.am: -lib_SOURCES += getnline.h -EXTRA_DIST += getndelim2.c +lib_SOURCES += getnline.h getnline.c Include: "getnline.h"