]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1171] line editing in ntpq/ntpdc
authorDave Hart <hart@ntp.org>
Sun, 3 May 2009 01:47:51 +0000 (01:47 +0000)
committerDave Hart <hart@ntp.org>
Sun, 3 May 2009 01:47:51 +0000 (01:47 +0000)
[Bug 1173] NMEA PPSAPI fails on Solaris

bk: 49fcf7c7BzZobbVdJuIWaq5RKyWb9A

ChangeLog
include/ntp_lineedit.h [new file with mode: 0644]
libntp/Makefile.am
libntp/ntp_lineedit.c [new file with mode: 0644]
m4/ntp_lineeditlibs.m4
ntpd/refclock_nmea.c
ntpdc/ntpdc.c
ntpq/ntpq.c
ports/winnt/libntp/libntp.vcproj
ports/winnt/ntpdc/ntpdc.vcproj
ports/winnt/ntpq/ntpq.vcproj

index f008ac99b010a7ac58fbe9955cf1af28a6353894..2413a75744b94a7b04ad45cf96af2b677c940cc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* [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)
diff --git a/include/ntp_lineedit.h b/include/ntp_lineedit.h
new file mode 100644 (file)
index 0000000..623c6f4
--- /dev/null
@@ -0,0 +1,13 @@
+
+/*
+ * 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);
+
index 790a8fb81e7ba8ea660e8c1ce53a14d2a0e52342..a7d78a408bd20d005973d8a17d7df490d795e3ee 100644 (file)
@@ -8,7 +8,7 @@ libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
        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 \
diff --git a/libntp/ntp_lineedit.c b/libntp/ntp_lineedit.c
new file mode 100644 (file)
index 0000000..aa40230
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * 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 */
+
index 07f24cdd9dd50ebffc860cdccb8aa63cd8cb38da..99c79211e8500e0373a8cc6f62ad63286b1cc991 100644 (file)
@@ -1,5 +1,5 @@
 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"],
@@ -13,43 +13,51 @@ AC_DEFUN([NTP_LINEEDITLIBS], [
        ;;
      *)
        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
      '')
@@ -61,31 +69,23 @@ AC_DEFUN([NTP_LINEEDITLIBS], [
        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])
@@ -94,9 +94,9 @@ AC_DEFUN([NTP_LINEEDITLIBS], [
         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
index 67e9e77d8774901884e7084fba1915900a548813..5de620820f7feedee5a3432e6c6c0870a6053a4d 100644 (file)
@@ -370,6 +370,7 @@ nmea_ppsapi(
                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
index 74cd12a1183b06c38df3689a954a3a093e0e7be9..6e9950f57bbf67f66836580b7e07f3862984c5a5 100644 (file)
@@ -12,6 +12,7 @@
 #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)
@@ -1124,33 +1116,20 @@ again:
 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();
 }
 
 
index 5f74200852858c3b7c71854f8c095f59f2692d08..428f4dc11ab21e77bf965b7d170711ced314b43d 100644 (file)
@@ -17,6 +17,7 @@
 #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)
@@ -1455,36 +1447,24 @@ doquery(
 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
index 53f637ac375fd4bedf412fee6e48f2ade5f8394b..97bfbe52a6dfa7fce136cfe9a561ed2c7be08977 100644 (file)
                                        />
                                </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"
                                >
index cee1866b7ae2481dd5cc33e23f8b39771ba64aaa..739e5833c05ae3d1685314c3d75cc635909e1338 100644 (file)
                        Name="Header Files"
                        Filter="h;hpp;hxx;hm;inl"
                        >
+                       <File
+                               RelativePath="..\..\..\include\ntp_lineedit.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\ntpdc\ntpdc.h"
                                >
index 7803454f12bb44bab79d6576a646e6fa1ecb5409..d044d65e92a841a997b5888cbee8781241e0c55a 100644 (file)
                        Name="Header Files"
                        Filter="h;hpp;hxx;hm;inl"
                        >
+                       <File
+                               RelativePath="..\..\..\include\ntp_lineedit.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\ntpq\ntpq.h"
                                >