summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Smith2008-03-07 21:49:03 +0000
committerBradley Smith2008-03-07 21:49:03 +0000
commite873d9aba5c545c1fa78e13a496baf6ac746f889 (patch)
treea653c2fe99ba60274f6394b4e0b943e445e0471d
parentAdd -pedantic-errors and -Werror flags to compile, and fix code to comply. (diff)
downloadgnurobots-e873d9aba5c545c1fa78e13a496baf6ac746f889.tar.gz
Add readline support to x11_plugin's commandline input.
Signed-off-by: Bradley Smith <brad@brad-smith.co.uk>
-rw-r--r--configure.ac32
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/x11plugin.c21
3 files changed, 53 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 9addd68..a034057 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,38 @@ if test "x$HAVE_GLIB2" = "xno"; then
AC_MSG_ERROR([GNU Robots requires GLib2 to compile.])
fi
+AC_CHECK_FUNC(tgetent,
+ [READLINE_EXTRA=],
+ [AC_CHECK_LIB(curses, tgetent,
+ [READLINE_EXTRA=-lcurses],
+ [AC_CHECK_LIB(ncurses, tgetent,
+ [READLINE_EXTRA=-lncurses],
+ [AC_CHECK_LIB(termcap, tgetent,
+ [READLINE_EXTRA=-ltermcap],
+ [AC_MSG_WARN(No Termcap or Curses library found)])
+ ])
+ ])
+ ])
+
+AC_CHECK_LIB(readline,readline,[READLINE_LIBS=-lreadline],
+ AC_MSG_ERROR([
+
+You need the GNU Readline library to build this program.
+
+]),[$READLINE_EXTRA])
+
+AC_CHECK_HEADER(readline/readline.h,[READLINE_CFLAGS=-I/usr/include/readline/],
+ AC_MSG_ERROR([
+
+You need the GNU Readline headers to build this program.
+
+]))
+
+READLINE_LIBS="$READLINE_LIBS $READLINE_EXTRA"
+
+AC_SUBST(READLINE_LIBS)
+AC_SUBST(READLINE_CFLAGS)
+
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f3d6283..36a2a6c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -30,7 +30,7 @@ else
X11_PLUGIN=
endif
-INCLUDES = $(GLIB2_CFLAGS) $(CURSES_CFLAGS) $(X_FLAGS) -I$(top_builddir)/include
+INCLUDES = $(GLIB2_CFLAGS) $(CURSES_CFLAGS) $(X_FLAGS) -I$(top_builddir)/include $(READLINE_CFLAGS)
pkglib_LTLIBRARIES = libgrobots-text.la $(CURSES_PLUGIN) $(X11_PLUGIN)
@@ -44,5 +44,5 @@ libgrobots_curses_la_LIBADD = $(GLIB2_LIBS) $(CURSES_LIBS)
libgrobots_x11_la_SOURCES = x11plugin.c
libgrobots_x11_la_LDFLAGS = -module -avoid-version
-libgrobots_x11_la_LIBADD = $(GLIB2_LIBS) $(X_LIBS)
+libgrobots_x11_la_LIBADD = $(GLIB2_LIBS) $(X_LIBS) $(READLINE_LIBS)
diff --git a/lib/x11plugin.c b/lib/x11plugin.c
index 4585be5..81bba80 100644
--- a/lib/x11plugin.c
+++ b/lib/x11plugin.c
@@ -27,6 +27,8 @@
#include "configs.h"
#include "x11plugin.h"
+#include <readline.h>
+
enum
{
ARG_0,
@@ -580,8 +582,23 @@ inline void x11_plugin_get_string (X11Plugin *x11,
/* You want me to write a text-box using xlib?
* You got to be kidding me
* */
- fputs (prompt, stdout);
- fgets (buff, len, stdin);
+/* fputs (prompt, stdout); */
+/* fgets (buff, len, stdin); */
+
+ char* line = (char*)NULL;
+
+ line = readline(prompt);
+
+ if(line && *line)
+ {
+ add_history(line);
+
+ g_strlcpy(buff, line, len);
+ }
+ else
+ buff = "";
+
+ free(line);
}
inline void x11_update_status (X11Plugin *x11,