From: Simon Josefsson Date: Thu, 11 Aug 2005 19:42:27 +0000 (+0000) Subject: Add readline. X-Git-Tag: cvs-readonly~3163 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=907eac00481355b563fd81872899eeea60417904;p=gnulib.git Add readline. --- diff --git a/ChangeLog b/ChangeLog index 3434d652f..1fe8fe87c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2005-08-11 Simon Josefsson + * modules/readline: New file. + * modules/strnlen (Files): Add strnlen.h. 2005-08-10 Simon Josefsson diff --git a/lib/ChangeLog b/lib/ChangeLog index 9cc09cefa..e872114b4 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2005-08-11 Simon Josefsson + + * readline.h, readline.c: New file. + 2005-08-11 Bruno Haible * strnlen.h (strnlen): Change parameter name to match comment. diff --git a/lib/readline.c b/lib/readline.c new file mode 100644 index 000000000..197262a29 --- /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 + if the real library is present on the system. */ + +/* Get specification. */ +#include "readline.h" + +#include +#include + +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; +} diff --git a/lib/readline.h b/lib/readline.h new file mode 100644 index 000000000..a5d339acc --- /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 +/* makes use of the FILE type without including + itself. */ +# include +# include +#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 */ diff --git a/m4/ChangeLog b/m4/ChangeLog index 57994d8b8..dda63abf4 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2005-08-11 Simon Josefsson + + * readline.m4: New file. + 2005-08-10 Simon Josefsson * strnlen.m4: New file. diff --git a/m4/readline.m4 b/m4/readline.m4 new file mode 100644 index 000000000..d9555070a --- /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 +#include ], + [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], [ + : +]) diff --git a/modules/readline b/modules/readline new file mode 100644 index 000000000..b5e7db316 --- /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