$(LIBXML2_CFLAGS)
endif HAVE_LIBXML2
+if HAVE_READLINE
+LIBISC_CFLAGS += \
+ $(READLINE_CFLAGS)
+endif HAVE_READLINE
+
LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la
LIBDNS_CFLAGS = \
bin_PROGRAMS = dig host nslookup
-nslookup_LDADD = \
- $(LDADD) \
- $(READLINE_LIB)
+nslookup_LDADD = \
+ $(LDADD)
+
+if HAVE_READLINE
+nslookup_LDADD += \
+ $(READLINE_LIBS)
+endif HAVE_READLINE
#include <isc/netaddr.h>
#include <isc/parseint.h>
#include <isc/print.h>
+#include <isc/readline.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include "dighost.h"
-#if defined(HAVE_READLINE)
-#if defined(HAVE_EDIT_READLINE_READLINE_H)
-#include <edit/readline/readline.h>
-#if defined(HAVE_EDIT_READLINE_HISTORY_H)
-#include <edit/readline/history.h>
-#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
-#elif defined(HAVE_EDITLINE_READLINE_H)
-#include <editline/readline.h>
-#elif defined(HAVE_READLINE_READLINE_H)
-/* Prevent deprecated functions being declared. */
-#define _FUNCTION_DEF 1
-/* Ensure rl_message() gets prototype. */
-#define USE_VARARGS 1
-#define PREFER_STDARG 1
-#include <readline/readline.h>
-#if defined(HAVE_READLINE_HISTORY_H)
-#include <readline/history.h>
-#endif /* if defined(HAVE_READLINE_HISTORY_H) */
-#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
-#endif /* if defined(HAVE_READLINE) */
-
static bool short_form = true, tcpmode = false, tcpmode_set = false,
identify = false, stats = true, comments = true,
section_question = true, section_answer = true,
static void
get_next_command(void) {
- char *buf;
- char *ptr;
+ char cmdlinebuf[COMMSIZE];
+ char *cmdline, *ptr = NULL;
- fflush(stdout);
- buf = isc_mem_allocate(mctx, COMMSIZE);
isc_app_block();
if (interactive) {
-#ifdef HAVE_READLINE
- ptr = readline("> ");
- if (ptr != NULL) {
+ cmdline = ptr = readline("> ");
+ if (ptr != NULL && *ptr != 0) {
add_history(ptr);
}
-#else /* ifdef HAVE_READLINE */
- fprintf(stderr, "> ");
- fflush(stderr);
- ptr = fgets(buf, COMMSIZE, stdin);
-#endif /* ifdef HAVE_READLINE */
} else {
- ptr = fgets(buf, COMMSIZE, stdin);
+ cmdline = fgets(cmdlinebuf, COMMSIZE, stdin);
}
isc_app_unblock();
- if (ptr == NULL) {
+ if (cmdline == NULL) {
in_use = false;
} else {
- do_next_command(ptr);
+ do_next_command(cmdline);
}
-#ifdef HAVE_READLINE
- if (interactive) {
+ if (ptr != NULL) {
free(ptr);
}
-#endif /* ifdef HAVE_READLINE */
- isc_mem_free(mctx, buf);
}
ISC_NORETURN static void
$(LIBISCCFG_LIBS) \
$(LIBIRS_LIBS) \
$(LIBBIND9_LIBS) \
- $(READLINE_LIB) \
$(GSSAPI_LIBS) \
$(KRB5_LIBS)
+if HAVE_READLINE
+LDADD += \
+ $(READLINE_LIBS)
+endif
+
bin_PROGRAMS = nsupdate
#include <isc/portset.h>
#include <isc/print.h>
#include <isc/random.h>
+#include <isc/readline.h>
#include <isc/region.h>
#include <isc/sockaddr.h>
#include <isc/socket.h>
#include <bind9/getaddresses.h>
-#if defined(HAVE_READLINE)
-#if defined(HAVE_EDIT_READLINE_READLINE_H)
-#include <edit/readline/readline.h>
-#if defined(HAVE_EDIT_READLINE_HISTORY_H)
-#include <edit/readline/history.h>
-#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
-#elif defined(HAVE_EDITLINE_READLINE_H)
-#include <editline/readline.h>
-#else /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
-/* Prevent deprecated functions being declared. */
-#define _FUNCTION_DEF 1
-/* Ensure rl_message() gets prototype. */
-#define USE_VARARGS 1
-#define PREFER_STDARG 1
-#include <readline/history.h>
-#include <readline/readline.h>
-#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
-#endif /* if defined(HAVE_READLINE) */
-
#define MAXCMD (128 * 1024)
#define MAXWIRE (64 * 1024)
#define PACKETSIZE ((64 * 1024) - 1)
get_next_command(void) {
uint16_t result = STATUS_QUIT;
char cmdlinebuf[MAXCMD];
- char *cmdline;
+ char *cmdline = NULL, *ptr = NULL;
isc_app_block();
if (interactive) {
-#ifdef HAVE_READLINE
- cmdline = readline("> ");
- if (cmdline != NULL) {
- add_history(cmdline);
- }
-#else /* ifdef HAVE_READLINE */
- fprintf(stdout, "> ");
- fflush(stdout);
- cmdline = fgets(cmdlinebuf, MAXCMD, input);
-#endif /* ifdef HAVE_READLINE */
+ cmdline = ptr = readline("> ");
+ if (ptr != NULL && *ptr != 0) {
+ add_history(ptr);
+ }
} else {
cmdline = fgets(cmdlinebuf, MAXCMD, input);
}
(void)nsu_strsep(&tmp, "\r\n");
result = do_next_command(cmdline);
}
-#ifdef HAVE_READLINE
- if (interactive) {
- free(cmdline);
+ if (ptr != NULL) {
+ free(ptr);
}
-#endif /* ifdef HAVE_READLINE */
+
return (result);
}
#
AC_CHECK_FUNCS([strlcpy strlcat])
-AC_SUBST(READLINE_LIB)
-AC_ARG_WITH(readline,
- AS_HELP_STRING([--with-readline[=LIBSPEC]],
- [specify readline library [default auto]]),
- use_readline="$withval", use_readline="auto")
-case "$use_readline" in
-no) ;;
-*)
- saved_LIBS="$LIBS"
- case "$use_readline" in
- yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
- *) try_readline="$use_readline"
- esac
- for readline in "$try_readline" $or_readline
- do
- LIBS="$readline"
- AC_MSG_NOTICE(checking for readline with $readline)
- AC_CHECK_FUNCS(readline)
- if test "yes" = "$ac_cv_func_readline"
- then
- READLINE_LIB="$readline"
- break
- fi
- for lib in -lterminfo -ltermcap -lncurses -lcurses
- do
- AC_MSG_NOTICE(checking for readline with $readline $lib)
- unset ac_cv_func_readline
- LIBS="$readline $lib"
- AC_CHECK_FUNCS(readline)
- if test "yes" = "$ac_cv_func_readline"
- then
- READLINE_LIB="$readline $lib"
- break
- fi
- done
- if test "yes" = "$ac_cv_func_readline"
- then
- break
- fi
- done
- if test "auto" != "$use_readline" &&
- test "X$READLINE_LIB" = "X"
- then
- AC_MSG_ERROR([The readline library was not found.])
- fi
- LIBS="$saved_LIBS"
- ;;
-esac
-if test "yes" = "$ac_cv_func_readline"
-then
- case "$READLINE_LIB" in
- *edit*)
- AC_CHECK_HEADERS(editline/readline.h)
- AC_CHECK_HEADERS(edit/readline/readline.h)
- AC_CHECK_HEADERS(edit/readline/history.h)
- ;;
- esac
- AC_CHECK_HEADERS(readline/readline.h)
- AC_CHECK_HEADERS(readline/history.h)
-fi
+#
+# Check for readline support
+#
+
+AC_ARG_WITH([readline],
+ [AS_HELP_STRING([--with-readline=yes|no|libedit|readline],
+ [specify readline library [default auto]])],
+ [], [with_readline="auto"])
+
+AS_CASE([$with_readline],
+ [no],[],
+ [auto],
+ [PKG_CHECK_MODULES([READLINE], [libedit],
+ [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])],
+ [PKG_CHECK_MODULES([READLINE], [editline],
+ [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support.])],
+ [PKG_CHECK_MODULES([READLINE], [readline],
+ [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support.])],
+ [AS_IF([test "$with_readline" = "yes"],
+ [AC_MSG_ERROR([readline support requested, but none of the libraries have been found.])])])])])],
+ [libedit],
+ [PKG_CHECK_MODULES([READLINE], [libedit],
+ [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])])],
+ [editline],
+ [PKG_CHECK_MODULES([READLINE], [editline],
+ [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support])])],
+ [readline],
+ [PKG_CHECK_MODULES([READLINE], [readline],
+ [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support])])],
+ [AC_MSG_ERROR([Unknown readline '$with_readline' library requested.])])
+AM_CONDITIONAL([HAVE_READLINE], [test -n "$READLINE_LIBS"])
+AC_SUBST([READLINE_CFLAGS])
+AC_SUBST([READLINE_LIBS])
#
# Security Stuff
include/isc/radix.h \
include/isc/random.h \
include/isc/ratelimiter.h \
+ include/isc/readline.h \
include/isc/refcount.h \
include/isc/regex.h \
include/isc/region.h \
--- /dev/null
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#pragma once
+
+/*
+ * A little wrapper around readline(), add_history() and free() to make using
+ * the readline code simpler.
+ */
+
+#if defined(HAVE_READLINE_LIBEDIT)
+#include <editline/readline.h>
+#elif defined(HAVE_READLINE_EDITLINE)
+#include <editline.h>
+#elif defined(HAVE_READLINE_READLINE)
+/* Prevent deprecated functions being declared. */
+#define _FUNCTION_DEF 1
+/* Ensure rl_message() gets prototype. */
+#define USE_VARARGS 1
+#define PREFER_STDARG 1
+#include <readline/history.h>
+#include <readline/readline.h>
+#endif
+
+#if !defined(HAVE_READLINE_LIBEDIT) && !defined(HAVE_READLINE_EDITLINE) && \
+ !defined(HAVE_READLINE_READLINE)
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define RL_MAXCMD (128 * 1024)
+
+static inline char *
+readline(const char *prompt) {
+ char *line, *buf = malloc(RL_MAXCMD);
+ fprintf(stdout, "%s", prompt);
+ fflush(stdout);
+ line = fgets(buf, RL_MAXCMD, stdin);
+ if (line == NULL) {
+ free(buf);
+ return (NULL);
+ }
+ return (buf);
+};
+
+#define add_history(line)
+
+#endif
./lib/isc/include/isc/radix.h C 2007,2008,2013,2014,2016,2018,2019,2020
./lib/isc/include/isc/random.h C 1999,2000,2001,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020
./lib/isc/include/isc/ratelimiter.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2018,2019,2020
+./lib/isc/include/isc/readline.h C 2020
./lib/isc/include/isc/refcount.h C 2001,2003,2004,2005,2006,2007,2009,2016,2017,2018,2019,2020
./lib/isc/include/isc/regex.h C 2013,2016,2018,2019,2020
./lib/isc/include/isc/region.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2013,2016,2018,2019,2020