Mercurial > hg > octave-nkf > gnulib-hg
changeset 6023:dc4cf8f3232e
Add readline.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Thu, 11 Aug 2005 19:42:27 +0000 |
parents | 3e49ae01bca0 |
children | 1bb00e100009 |
files | ChangeLog lib/ChangeLog lib/readline.c lib/readline.h m4/ChangeLog m4/readline.m4 modules/readline |
diffstat | 7 files changed, 184 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2005-08-11 Simon Josefsson <jas@extundo.com> + * modules/readline: New file. + * modules/strnlen (Files): Add strnlen.h. 2005-08-10 Simon Josefsson <jas@extundo.com>
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2005-08-11 Simon Josefsson <jas@extundo.com> + + * readline.h, readline.c: New file. + 2005-08-11 Bruno Haible <bruno@clisp.org> * strnlen.h (strnlen): Change parameter name to match comment.
new file mode 100644 --- /dev/null +++ b/lib/readline.c @@ -0,0 +1,51 @@ +/* readline.c --- Simple implementation of readline. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by Simon Josefsson + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +/* This module is intended to be used when the application only need + the readline interface. If you need more functions from the + readline library, it is recommended to require the readline library + (or improve this module) rather than #if-protect part of your + application (doing so would add assumptions of this module into + your application). The application should use #include + "readline.h", that header file will include <readline/readline.h> + if the real library is present on the system. */ + +/* Get specification. */ +#include "readline.h" + +#include <stdio.h> +#include <getline.h> + +char * +readline (const char *prompt) +{ + char *out = NULL; + size_t size = 0; + + if (prompt) + fputs (prompt, stdout); + + if (getline (&out, &size, stdin) < 0) + return NULL; + + return out; +}
new file mode 100644 --- /dev/null +++ b/lib/readline.h @@ -0,0 +1,35 @@ +/* readline.h --- Simple implementation of readline. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by Simon Josefsson + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef GL_READLINE_H +#define GL_READLINE_H + +#if HAVE_READLINE_READLINE_H +/* <readline/readline.h> makes use of the FILE type without including + <stdio.h> itself. */ +# include <stdio.h> +# include <readline/readline.h> +#else +/* Prints a prompt PROMPT and then reads and returns a single line of + text from the user. If PROMPT is NULL or the empty string, no + prompt is displayed. The returned line is allocated with malloc; + the caller should free the line when it has finished with it. */ +extern char *readline (const char *prompt); +#endif + +#endif /* GL_READLINE_H */
--- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2005-08-11 Simon Josefsson <jas@extundo.com> + + * readline.m4: New file. + 2005-08-10 Simon Josefsson <jas@extundo.com> * strnlen.m4: New file.
new file mode 100644 --- /dev/null +++ b/m4/readline.m4 @@ -0,0 +1,63 @@ +# readline.m4 serial 1 +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_READLINE], +[ + AC_LIBSOURCES([readline.c, readline.h]) + + dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + + dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and + dnl INCREADLINE accordingly. + AC_LIB_LINKFLAGS_BODY([readline]) + + dnl Add $INCREADLINE to CPPFLAGS before performing the following checks, + dnl because if the user has installed libreadline and not disabled its use + dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK + dnl will then succeed. + am_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE]) + + AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [ + gl_cv_lib_readline=no + am_save_LIBS="$LIBS" + LIBS="$LIBS $LIBREADLINE" + AC_TRY_LINK([#include <stdio.h> +#include <readline/readline.h>], + [readline((char*)0);], + gl_cv_lib_readline=yes) + LIBS="$am_save_LIBS" + ]) + if test "$gl_cv_lib_readline" = yes; then + AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline() library.]) + fi + if test "$gl_cv_lib_readline" = yes; then + AC_MSG_CHECKING([how to link with libreadline]) + AC_MSG_RESULT([$LIBREADLINE]) + else + dnl If $LIBREADLINE didn't lead to a usable library, we don't need $INCREADLINE + dnl either. + CPPFLAGS="$am_save_CPPFLAGS" + LIBREADLINE= + LTLIBREADLINE= + fi + AC_SUBST(LIBREADLINE) + AC_SUBST(LTLIBREADLINE) + + AC_CHECK_HEADERS(readline/readline.h) + + if test $gl_cv_lib_readline = no; then + AC_LIBOBJ(readline) + gl_PREREQ_READLINE + fi +]) + +# Prerequisites of lib/readline.c. +AC_DEFUN([gl_PREREQ_READLINE], [ + : +])
new file mode 100644 --- /dev/null +++ b/modules/readline @@ -0,0 +1,25 @@ +Description: +Simple implementation of readline. + +Files: +lib/readline.h +lib/readline.c +m4/readline.m4 +m4/lib-link.m4 + +Depends-on: +getline + +configure.ac: +gl_FUNC_READLINE + +Makefile.am: + +Include: +"readline.h" + +License: +GPL + +Maintainer: +Simon Josefsson