gjs r147 - in trunk: . modules
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gjs r147 - in trunk: . modules
- Date: Mon, 26 Jan 2009 16:31:59 +0000 (UTC)
Author: johan
Date: Mon Jan 26 16:31:59 2009
New Revision: 147
URL: http://svn.gnome.org/viewvc/gjs?rev=147&view=rev
Log:
Bug 569178 â Add readline support to the console module
Modified:
trunk/Makefile-modules.am
trunk/configure.ac
trunk/modules/console.c
Modified: trunk/Makefile-modules.am
==============================================================================
--- trunk/Makefile-modules.am (original)
+++ trunk/Makefile-modules.am Mon Jan 26 16:31:59 2009
@@ -50,6 +50,10 @@
console_la_LDFLAGS = \
$(JS_NATIVE_MODULE_LDFLAGS)
+if HAVE_READLINE
+console_la_LIBADD += -lreadline
+endif
+
console_la_SOURCES = \
modules/console.h \
modules/console.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Jan 26 16:31:59 2009
@@ -129,6 +129,21 @@
PKG_CHECK_MODULES([GJS_GI], [$gjs_gi_packages])
GJS_GI_CFLAGS="$GJS_GI_CFLAGS -I$js_include_dir"
+# readline
+AC_MSG_CHECKING([whether readline support is requested])
+AC_ARG_WITH(readline,
+ AC_HELP_STRING([--without-readline],
+ [do not support fancy command line editing]),
+ [HAVE_READLINE="$withval"], [HAVE_READLINE=yes])
+case "$HAVE_READLINE" in yes);; no);; *)HAVE_READLINE=yes;; esac
+AC_MSG_RESULT($HAVE_READLINE)
+if test "$HAVE_READLINE" = yes ; then
+ AC_CHECK_LIB(readline, add_history)
+ AC_CHECK_HEADERS([readline/readline.h])
+fi
+AM_CONDITIONAL([HAVE_READLINE], [test x$HAVE_READLINE = xyes])
+AC_SUBST([HAVE_READLINE])
+
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
Modified: trunk/modules/console.c
==============================================================================
--- trunk/modules/console.c (original)
+++ trunk/modules/console.c Mon Jan 26 16:31:59 2009
@@ -38,8 +38,16 @@
*
* ***** END LICENSE BLOCK ***** */
+#include "config.h"
+
+#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_LIBREADLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+
#include <jsapi.h>
#include <jsstddef.h> /* PTRDIFF */
#include <glib.h>
@@ -118,6 +126,22 @@
g_free(prefix);
}
+#ifdef HAVE_LIBREADLINE
+static JSBool
+gjs_console_readline(JSContext *cx, char *bufp, FILE *file, const char *prompt)
+{
+ char *line;
+ line = readline(prompt);
+ if (line && line[0] != '\0')
+ add_history(line);
+ if (!line) {
+ return JS_FALSE;
+ }
+ strcpy(bufp, line);
+ free(line);
+ return JS_TRUE;
+}
+#else
static JSBool
gjs_console_readline(JSContext *cx, char *bufp, FILE *file, const char *prompt)
{
@@ -129,6 +153,7 @@
strcpy(bufp, line);
return JS_TRUE;
}
+#endif
JSBool
gjs_console_interact(JSContext *context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]