+* [Bug 1171] line editing libs found without headers (Solaris 11)
+* [Bug 1173] NMEA refclock fails with Solaris PPSAPI
(4.2.5p170) 2009/05/02 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 1152] adjust PARSE to new refclock_pps logic
* Include (4.2.4p7-RC5)
--- /dev/null
+
+/*
+ * ntp_lineedit.h - generic interface to various line editing libs
+ */
+
+int ntp_readline_init(const char *prompt);
+void ntp_readline_uninit(void);
+
+/*
+ * strings returned by ntp_readline go home to free()
+ */
+char * ntp_readline(int *pcount);
+
clocktypes.c decodenetnum.c dofptoa.c dolfptoa.c emalloc.c \
findconfig.c fptoa.c fptoms.c getopt.c hextoint.c \
hextolfp.c humandate.c icom.c inttoa.c iosignal.c \
- lib_strbuf.c machines.c memmove.c mfptoa.c \
+ lib_strbuf.c machines.c memmove.c mfptoa.c ntp_lineedit.c \
mfptoms.c mktime.c modetoa.c mstolfp.c msutotsf.c msyslog.c netof.c \
ntp_rfc2553.c numtoa.c numtohost.c octtoint.c prettydate.c \
ntp_random.c recvbuff.c refnumtoa.c snprintf.c socktoa.c socktohost.c \
--- /dev/null
+/*
+ * ntp_lineedit.c - generic interface to various line editing libs
+ */
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(HAVE_READLINE_HISTORY)
+ #include <readline/readline.h>
+ #include <readline/history.h>
+#else
+ #if defined(HAVE_HISTEDIT_H)
+ #include <histedit.h>
+ #endif
+#endif
+
+#include "ntp.h"
+#include "ntp_lineedit.h"
+
+#define MAXEDITLINE 512
+
+/*
+ * external references
+ */
+
+extern char * progname;
+
+/*
+ * globals, private prototypes
+ */
+
+static int ntp_readline_initted;
+static char * lineedit_prompt;
+
+
+#if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+
+ static EditLine * ntp_el;
+ static History * ntp_hist;
+ static HistEvent hev;
+
+ char * ntp_prompt_callback(EditLine *);
+
+#endif /* !HAVE_READLINE_HISTORY_H && HAVE_HISTEDIT_H */
+
+
+/*
+ * ntp_readline_init - setup, set or reset prompt string
+ */
+
+int
+ntp_readline_init(
+ const char * prompt
+ )
+{
+ int success;
+
+ success = 1;
+
+ if (prompt) {
+ if (lineedit_prompt)
+ free(lineedit_prompt);
+ lineedit_prompt = strdup(prompt);
+ }
+
+ #if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+
+ if (NULL == ntp_el) {
+
+ ntp_el = el_init(progname, stdin, stdout, stderr);
+ if (ntp_el) {
+
+ el_set(ntp_el, EL_PROMPT,
+ ntp_prompt_callback);
+ el_set(ntp_el, EL_EDITOR, "emacs");
+
+ ntp_hist = history_init();
+
+ if (NULL == ntp_hist) {
+
+ fprintf(stderr,
+ "history_init(): %s\n",
+ strerror(errno));
+ fflush(stderr);
+
+ el_end(ntp_el);
+ ntp_el = NULL;
+
+ success = 0;
+
+ } else {
+ memset(&hev, 0, sizeof hev);
+
+ history(ntp_hist, &hev,
+ H_SETSIZE, 128);
+
+ el_set(ntp_el, EL_HIST,
+ history, ntp_hist);
+
+ /* use any .editrc */
+ el_source(ntp_el, NULL);
+ }
+
+ } else
+ success = 0;
+ }
+
+ #endif /* !HAVE_READLINE_HISTORY && HAVE_HISTEDIT_H */
+
+ ntp_readline_initted = success;
+
+ return success;
+}
+
+
+/*
+ * ntp_readline_uninit - release resources
+ */
+
+void
+ntp_readline_uninit(
+ void
+ )
+{
+ #if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+
+ if (ntp_el) {
+ el_end(ntp_el);
+ ntp_el = NULL;
+
+ history_end(ntp_hist);
+ ntp_hist = NULL;
+ }
+
+ #endif /* !HAVE_READLINE_HISTORY && HAVE_HISTEDIT_H */
+
+ if (lineedit_prompt) {
+ free(lineedit_prompt);
+ lineedit_prompt = NULL;
+ }
+
+ ntp_readline_initted = 0;
+}
+
+
+/*
+ * ntp_readline - read a line with the line editor available
+ *
+ * The string returned must be released with free()
+ */
+
+char *
+ntp_readline(
+ int * pcount
+ )
+{
+ char * line;
+#if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+ const char * cline;
+#endif
+
+ if (!ntp_readline_initted)
+ return NULL;
+
+ *pcount = 0;
+
+ #if defined(HAVE_READLINE_HISTORY)
+
+ line = readline(lineedit_prompt ? lineedit_prompt : "");
+ if (NULL != line) {
+ if (*line) {
+ add_history(line);
+ *pcount = strlen(line);
+ } else {
+ free(line);
+ line = NULL;
+ }
+ }
+
+ #endif
+ #if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+
+ cline = el_gets(ntp_el, pcount);
+
+ if (NULL != cline && *cline) {
+ history(ntp_hist, &hev, H_ENTER, cline);
+ *pcount = strlen(cline);
+ line = strdup(cline);
+ } else
+ line = NULL;
+
+ #else /* stone hammers */
+ {
+ char line_buf[MAXEDITLINE];
+
+ if (lineedit_prompt) {
+ #ifdef VMS
+ /* work around problem mixing stdout & stderr */
+ fputs("",stdout);
+ #endif
+
+ fputs(lineedit_prompt, stderr);
+ fflush(stderr);
+ }
+
+ line = fgets(line_buf, sizeof line_buf, stdin);
+ if (NULL != line && *line) {
+ *pcount = strlen(line);
+ line = strdup(line);
+ } else
+ line = NULL;
+ }
+ #endif /* stone hammers */
+
+ return line;
+}
+
+
+#if !defined(HAVE_READLINE_HISTORY) && defined(HAVE_HISTEDIT_H)
+ char *
+ ntp_prompt_callback(
+ EditLine *el
+ )
+ {
+ UNUSED_ARG(el);
+
+ return lineedit_prompt;
+ }
+#endif /* !HAVE_READLINE_HISTORY_H && HAVE_HISTEDIT_H */
+
AC_DEFUN([NTP_LINEEDITLIBS], [
- ORIG_LIBS="$LIBS"
+ NTP_ORIG_LIBS="$LIBS"
AC_ARG_WITH([lineeditlibs],
[AC_HELP_STRING([--with-lineeditlibs], [edit,editline (readline may be specified if desired)])],
[use_lineeditlibs="$withval"],
;;
*)
for lineedit_lib in `echo $use_lineeditlibs | sed -e 's/,/ /'`; do
- for term_lib in "" termcap curses ncurses; do
- case "$term_lib" in
- '') TRY_LIB="-l$lineedit_lib" ;;
- *) TRY_LIB="-l$lineedit_lib -l$term_lib" ;;
- esac
- LIBS="$ORIG_LIBS $TRY_LIB"
- AC_MSG_CHECKING([for readline() with $TRY_LIB])
- AC_TRY_LINK_FUNC([readline], [ntp_lib_lineedit="$TRY_LIB"])
- case "$ntp_lib_lineedit" in
- '')
- AC_MSG_RESULT([no])
- ;;
- *) # Use readline()
- AC_MSG_RESULT([yes])
- break
- ;;
- esac
- AC_MSG_CHECKING([for el_gets() with $TRY_LIB])
- AC_TRY_LINK_FUNC([el_gets], [ntp_lib_lineedit="$TRY_LIB"])
+ for term_lib in "" termcap curses ncurses; do
+ case "$term_lib" in
+ '')
+ TRY_LIB="-l$lineedit_lib"
+ ;;
+ *) TRY_LIB="-l$lineedit_lib -l$term_lib"
+ esac # $term_lib
+ LIBS="$NTP_ORIG_LIBS $TRY_LIB"
+ AC_MSG_CHECKING([for readline() with $TRY_LIB])
+ AC_TRY_LINK_FUNC([readline], [ntp_lib_lineedit="$TRY_LIB"])
+ case "$ntp_lib_lineedit" in
+ '')
+ AC_MSG_RESULT([no])
+ ;;
+ *)
+ # Use readline()
+ AC_MSG_RESULT([yes])
+ break
+ esac # $ntp_lib_lineedit
+ case "$term_lib" in
+ '')
+ # do not try el_gets without a terminal library
+ ;;
+ *)
+ AC_MSG_CHECKING([for el_gets() with $TRY_LIB])
+ AC_TRY_LINK_FUNC([el_gets], [ntp_lib_lineedit="$TRY_LIB"])
+ case "$ntp_lib_lineedit" in
+ '')
+ AC_MSG_RESULT([no])
+ ;;
+ *) # Use el_gets()
+ AC_MSG_RESULT([yes])
+ break
+ ;;
+ esac # $ntp_lib_lineedit
+ esac # $term_lib
+ done
case "$ntp_lib_lineedit" in
- '')
- AC_MSG_RESULT([no])
- ;;
- *) # Use el_gets()
- AC_MSG_RESULT([yes])
- break
- ;;
+ '') ;;
+ *) break ;;
esac
- done
- case "$ntp_lib_lineedit" in
- '') ;;
- *) break ;;
- esac
done
- LIBS="$ORIG_LIBS"
+ LIBS="$NTP_ORIG_LIBS"
;;
- esac
+ esac # $use_lineeditlibs
case "$ntp_lib_lineedit" in
'')
EDITLINE_LIBS="$ntp_lib_lineedit"
AC_SUBST(EDITLINE_LIBS)
;;
- esac
+ esac # $ntp_lib_lineedit
case "$ntp_lib_lineedit" in
no)
;;
- -ledit)
- AC_DEFINE(HAVE_LIBEDIT, 1,
- [Define if you have libedit])
- # we want to also check for readline.h
- AC_CHECK_HEADERS(histedit.h)
- ;;
- -leditline)
- AC_MSG_WARN([editline is not yet supported])
- ;;
*)
- AC_DEFINE(HAVE_LIBREADLINE, 1,
- [Define if you have a readline compatible library])
- AC_CHECK_HEADERS(readline.h readline/readline.h)
+ dnl AC_DEFINE(HAVE_LIBREADLINE, 1,
+ dnl [Define if you have a readline compatible library])
+ AC_CHECK_HEADERS([readline.h readline/readline.h histedit.h])
+ AC_CHECK_HEADERS([history.h readline/history.h])
AC_MSG_CHECKING([whether readline supports history])
ntp_lib_lineedit_history="no"
ORIG_LIBS="$LIBS"
LIBS="$ORIG_LIBS $ntp_lib_lineedit"
- AC_TRY_LINK_FUNC(add_history, ntp_lib_lineedit_history="yes")
+ AC_TRY_LINK_FUNC([add_history], [ntp_lib_lineedit_history="yes"])
LIBS="$ORIG_LIBS"
AC_MSG_RESULT([$ntp_lib_lineedit_history])
yes)
AC_DEFINE(HAVE_READLINE_HISTORY, 1,
[Define if your readline library has \`add_history'])
- AC_CHECK_HEADERS(history.h readline/history.h)
- ;;
- esac
- ;;
- esac
+ esac # $ntp_lib_lineedit_history
+ esac # $ntp_lib_lineedit
+ dnl when oldest supported autoconf has AS_UNSET
+ dnl AS_UNSET([NTP_ORIG_LIBS TRY_LIB use_lineeditlibs])
+ $as_unset NTP_ORIG_LIBS TRY_LIB use_lineeditlibs
])dnl
return (0);
}
memset(&up->pps_params, 0, sizeof(pps_params_t));
+ up->pps_params.api_version = PPS_API_VERS_1;
if (enb_clear)
up->pps_params.mode = capability & PPS_CAPTURECLEAR;
else
#include "ntp_select.h"
#include "ntp_io.h"
#include "ntp_stdlib.h"
+#include "ntp_lineedit.h"
/* Don't include ISC's version of IPv6 variables and structures */
#define ISC_IPV6_H 1
#include "isc/net.h"
# endif /* OPENSSL */
#endif /* SYS_WINNT */
-#if defined(HAVE_LIBREADLINE)
-# include <readline/readline.h>
-# include <readline/history.h>
-#endif /* HAVE_LIBREADLINE */
-
-#if defined (HAVE_LIBEDIT)
-# include <histedit.h>
-#endif /* HAVE_LIBEDIT */
-
#ifdef SYS_VXWORKS
/* vxWorks needs mode flag -casey*/
# define open(name, flags) open(name, flags, 0777)
static void
getcmds(void)
{
-#if defined(HAVE_LIBREADLINE)
- char *line;
+ char * line;
+ int count;
+
+ ntp_readline_init(interactive ? prompt : NULL);
for (;;) {
- if ((line = readline(interactive?prompt:"")) == NULL) return;
- if (*line) add_history(line);
+ line = ntp_readline(&count);
+ if (NULL == line)
+ break;
docmd(line);
free(line);
}
-#else /* not (HAVE_LIBREADLINE) */
- char line[MAXLINE];
- for (;;) {
- if (interactive) {
-#ifdef VMS /* work around a problem with mixing stdout & stderr */
- fputs("",stdout);
-#endif
- (void) fputs(prompt, stderr);
- (void) fflush(stderr);
- }
-
- if (fgets(line, sizeof line, stdin) == NULL)
- return;
-
- docmd(line);
- }
-#endif /* not HAVE_LIBREADLINE || HAVE_LIBEDIT */
+ ntp_readline_uninit();
}
#include "ntp_select.h"
#include "ntp_stdlib.h"
#include "ntp_assert.h"
+#include "ntp_lineedit.h"
/* Don't include ISC's version of IPv6 variables and structures */
#define ISC_IPV6_H 1
#include "isc/net.h"
# endif /* OPENSSL */
#endif /* SYS_WINNT */
-#if defined(HAVE_LIBREADLINE)
-# include <readline/readline.h>
-# include <readline/history.h>
-#endif /* HAVE_LIBREADLINE */
-
-#if defined(HAVE_LIBEDIT)
-# include <histedit.h>
-#endif /* HAVE_LIBEDIT */
-
#ifdef SYS_VXWORKS
/* vxWorks needs mode flag -casey*/
# define open(name, flags) open(name, flags, 0777)
static void
getcmds(void)
{
-#if defined(HAVE_LIBREADLINE)
- char *line;
+ char * line;
+ int count;
+
+ ntp_readline_init(interactive ? prompt : NULL);
for (;;) {
- if ((line = readline(interactive?prompt:"")) == NULL) return;
- if (*line) add_history(line);
+ line = ntp_readline(&count);
+ if (NULL == line)
+ break;
docmd(line);
free(line);
}
-#else /* not (HAVE_LIBREADLINE) */
- char line[MAXLINE];
- for (;;) {
- if (interactive) {
-#ifdef VMS /* work around a problem with mixing stdout & stderr */
- fputs("",stdout);
-#endif
- (void) fputs(prompt, stderr);
- (void) fflush(stderr);
- }
-
- if (fgets(line, sizeof line, stdin) == NULL)
- return;
-
- docmd(line);
- }
-#endif /* not (HAVE_LIBREADLINE || HAVE_LIBEDIT) */
+ ntp_readline_uninit();
}
#endif /* !BUILD_AS_LIB */
+
#if !defined(SYS_WINNT) && !defined(BUILD_AS_LIB)
/*
* abortcmd - catch interrupts and abort the current command
/>
</FileConfiguration>
</File>
+ <File
+ RelativePath="..\..\..\libntp\ntp_lineedit.c"
+ >
+ </File>
<File
RelativePath="..\..\..\libntp\ntp_random.c"
>
RelativePath="..\include\ntp_iocompletionport.h"
>
</File>
+ <File
+ RelativePath="..\..\..\include\ntp_lineedit.h"
+ >
+ </File>
<File
RelativePath="..\..\..\include\ntp_machine.h"
>
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
+ <File
+ RelativePath="..\..\..\include\ntp_lineedit.h"
+ >
+ </File>
<File
RelativePath="..\..\..\ntpdc\ntpdc.h"
>
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
+ <File
+ RelativePath="..\..\..\include\ntp_lineedit.h"
+ >
+ </File>
<File
RelativePath="..\..\..\ntpq\ntpq.h"
>