1275970ScyAC_DEFUN([NTP_LINEEDITLIBS], [
2275970Scy    NTP_ORIG_LIBS="$LIBS"
3275970Scy    AC_ARG_WITH(
4275970Scy	[lineeditlibs],
5275970Scy	[AS_HELP_STRING(
6275970Scy	    [--with-lineeditlibs],
7275970Scy	    [edit,editline (readline may be specified if desired)]
8275970Scy	)],
9275970Scy	[use_lineeditlibs="$withval"],
10275970Scy	[use_lineeditlibs="edit,editline"]
11275970Scy    )
12275970Scy    AC_MSG_CHECKING([line editing libraries])
13275970Scy    AC_MSG_RESULT([$use_lineeditlibs])
14275970Scy    case "$use_lineeditlibs" in
15275970Scy     no) 
16275970Scy	ntp_lib_lineedit=no
17275970Scy	;;
18275970Scy     *)
19275970Scy	for lineedit_lib in `echo $use_lineeditlibs | sed -e 's/,/ /'`; do
20275970Scy	    for term_lib in "" termcap curses ncurses; do
21275970Scy		case "$term_lib" in
22275970Scy		 '') 
23275970Scy		    TRY_LIB="-l$lineedit_lib"
24275970Scy		    ;;
25275970Scy		 *)
26275970Scy		    TRY_LIB="-l$lineedit_lib -l$term_lib"
27275970Scy		    ;;
28275970Scy		esac
29275970Scy		LIBS="$NTP_ORIG_LIBS $TRY_LIB"
30275970Scy		AC_MSG_CHECKING([for readline() with $TRY_LIB])
31275970Scy		AC_TRY_LINK_FUNC([readline], [ntp_lib_lineedit="$TRY_LIB"])
32275970Scy		case "$ntp_lib_lineedit" in
33275970Scy		 '')
34275970Scy		    AC_MSG_RESULT([no])
35275970Scy		    ;;
36275970Scy		 *) 
37275970Scy		    # Use readline()
38275970Scy		    AC_MSG_RESULT([yes])
39275970Scy		    break
40275970Scy		esac
41275970Scy		case "$term_lib" in
42275970Scy		 '')
43275970Scy		    # do not try el_gets without a terminal library
44275970Scy		    ;;
45275970Scy		 *)
46275970Scy		    AC_MSG_CHECKING([for el_gets() with $TRY_LIB])
47275970Scy		    AC_TRY_LINK_FUNC([el_gets], [ntp_lib_lineedit="$TRY_LIB"])
48275970Scy		    case "$ntp_lib_lineedit" in
49275970Scy		     '')
50275970Scy			AC_MSG_RESULT([no])
51275970Scy			;;
52275970Scy		     *) # Use el_gets()
53275970Scy			AC_MSG_RESULT([yes])
54275970Scy			break
55275970Scy			;;
56275970Scy		    esac	# $ntp_lib_lineedit
57275970Scy		esac		# $term_lib
58275970Scy	    done
59275970Scy	    case "$ntp_lib_lineedit" in
60275970Scy	     '')
61275970Scy		;;
62275970Scy	     *)
63275970Scy		break
64275970Scy		;;
65275970Scy	    esac
66275970Scy	done
67275970Scy	LIBS="$NTP_ORIG_LIBS"
68275970Scy	;;
69275970Scy    esac	# $use_lineeditlibs
70275970Scy
71275970Scy    case "$ntp_lib_lineedit" in
72275970Scy     '')
73275970Scy	ntp_lib_lineedit="no"
74275970Scy	;;
75275970Scy     no)
76275970Scy	;;
77275970Scy     *)
78275970Scy	EDITLINE_LIBS="$ntp_lib_lineedit"
79275970Scy	AC_SUBST([EDITLINE_LIBS])
80275970Scy	;;
81275970Scy    esac	# $ntp_lib_lineedit
82275970Scy
83275970Scy    case "$ntp_lib_lineedit" in
84275970Scy     no)
85275970Scy	;;
86275970Scy     *)
87275970Scy	AC_CHECK_HEADERS([readline.h readline/readline.h histedit.h])
88275970Scy	AC_CHECK_HEADERS([history.h readline/history.h])
89275970Scy
90275970Scy	case "$ac_cv_header_histedit_h" in
91275970Scy	 yes)
92275970Scy	    AC_CACHE_CHECK(
93275970Scy		[number of arguments to el_init()],
94275970Scy		[ntp_cv_el_init_args],
95275970Scy		[AC_COMPILE_IFELSE(
96275970Scy		    [AC_LANG_PROGRAM(
97275970Scy			[[
98275970Scy			    #include <stdio.h>
99275970Scy			    #include <histedit.h>
100275970Scy			]],
101275970Scy			[[
102275970Scy			    el_init("conftest", stdin, stdout, stderr);
103275970Scy			]]
104275970Scy		    )],
105275970Scy		    [ntp_cv_el_init_args=4],
106275970Scy		    [ntp_cv_el_init_args=3]
107275970Scy		)]
108275970Scy	    )
109275970Scy	    AC_DEFINE_UNQUOTED(
110275970Scy		[EL_INIT_ARGS], 
111275970Scy		[$ntp_cv_el_init_args],
112275970Scy		[number of args to el_init()]
113275970Scy		)
114275970Scy	esac
115275970Scy	
116275970Scy	AC_MSG_CHECKING([whether readline supports history])
117275970Scy	
118275970Scy	ntp_lib_lineedit_history="no"
119275970Scy	ORIG_LIBS="$LIBS"
120275970Scy	LIBS="$ORIG_LIBS $ntp_lib_lineedit"
121275970Scy	AC_TRY_LINK_FUNC([add_history], [ntp_lib_lineedit_history="yes"])
122275970Scy	LIBS="$ORIG_LIBS"
123275970Scy
124275970Scy	AC_MSG_RESULT([$ntp_lib_lineedit_history])
125275970Scy
126275970Scy	case "$ntp_lib_lineedit_history" in
127275970Scy	 yes)
128275970Scy	    AC_DEFINE([HAVE_READLINE_HISTORY], [1],
129275970Scy		[Define if your readline library has \`add_history'])
130275970Scy	esac
131275970Scy    esac	# $ntp_lib_lineedit
132275970Scy    AS_UNSET([NTP_ORIG_LIBS])
133275970Scy    AS_UNSET([ORIG_LIBS])
134275970Scy    AS_UNSET([TRY_LIB])
135275970Scy    AS_UNSET([use_lineeditlibs])
136275970Scy])dnl
137